﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Xml.Linq;
using System.Data.Common;
using System.Transactions;
using System.Collections.Generic;
using Thrift.Transport;
using Thrift.Protocol;
using Thrift.Route;
using MySql.Data.MySqlClient;
using MySql.Data.Types;
using Refresher;
using log4net;

namespace WebServiceSmart.Router
{
    public class DBImpl
    {
        private static string LISTBIAONAME = "biaorecordlist";
        private static string HEZUOHUOBANBIAONAME = "biaohezuoproperty";
        private static string DAISHOUBIAONAME = "biaodaishouproperty";
        private static string DELDAISHOUBIAONAME = "biaodeldaishouproperty";
        private static string OVERDAISHOUBIAONAME = "biaooverdaishouproperty";
        private static string GUASHIDAISHOUBIAONAME = "biaodeldaishouproperty";
        private static string GOODSBIAONAME = "biaorecordproperty";
        private static string DELGOODSBIAONAME = "biaodelrecordproperty";
        private static string OVERGOODSBIAONAME = "biaooverrecordproperty";
        private static string CUSTOMBIAONAME = "biaocustom";
        private static string DELCUSTOMBIAONAME = "biaodelcustom";
        private static string SENDCARIDBIAONAME = "biaorecordcarsend";
        private static string NOSENDCARIDBIAONAME = "biaorecordnocarsend";
        private static string WAIZHUANBIAONAME = "biaowaizhuan";
        private static string DAKUANRECORDBIAONAME = "biaodakuanrecord";
        private static string HUIZHANGRECORDBIAONAME = "biaohuizhangrecord";
        private static string EMPLOYEEBIAONAME = "biaoemployee";
        private static string SHOUCHIBIAONAME = "biaoshouchi";
        private static string CARBIAONAME = "biaocar";
        private static string DOWNUSERBIAONAME = "biaodownuser";

        private static string connectionRoutingString = "Data Source = qingguan.mysql.rds.aliyuncs.com; Database=qgwuliusystem;User ID =qingguan; Password=QG568895qg;port=3377;charset=utf8;";
     //   private static string connectionServerString = "Data Source=127.0.0.1;Database=account;User ID=root;Password=QG568895qg;port=3306;charset=utf8;";
        private static string MySqlPwd = "QG568895qg";

       // private static string connectionRoutingString = "Data Source=127.0.0.1;Database=qg_root_service;User ID=root;Password=123456;port=3306;charset=utf8;";
       // private static string connectionServerString = "Data Source=127.0.0.1;Database=account;User ID=root;Password=123456;port=3306;charset=utf8;";
      //  private static string MySqlPwd = "123456";

        private static string IDISNOTEXIST = "不存在";
        private static string IDISEXISTALD = "存在重票";
        private static string KEHUANPIAO_STATUS = "已到账";
        private static string IDIS_QXNOTOK = "(无权限)";
        private static string KEHUANPIAO_ALL_KEY = "CouldTrade_All_Info";
        private static string KEHUANPIAO_ID_KEY = "CouldTrade_All_Id";
        private static string INI_HUANPIAO_SETTING_OUTER = "DAISHOUJISUANOUTER";
        private static string INI_HUANPIAO_SETTING = "DAISHOUSETTING";
        private static string INI_HUANPIAO_SETTING_TYPE = "Type";
        private static string INI_HUANPIAO_SETTING_DBZ = "DanBiLvzi";
        private static string INI_HUANPIAO_SETTING_DBM = "DanBiLvmu";
        private static string INI_HUANPIAO_SETTING_HBZ = "HeBiLvzi";
        private static string INI_HUANPIAO_SETTING_HBM = "HeBiLvmu";
        private static string INI_HUANPIAO_SETTING_PJ = "PiaoJi";

        private static string INI_HUANPIAO_SETTING_TYPE_DB = "1";
        private static string INI_HUANPIAO_SETTING_TYPE_HB = "2";
        private static string INI_HUANPIAO_SETTING_TYPE_HZ = "3";

        private static string INI_HUANPIAO_DBCLOUMNAME_YS = "Biao_YushouData";
        private static string INI_HUANPIAO_DBCLOUMNAME_SS = "Biao_ShishouData";
        private static string INI_HUANPIAO_DBCLOUMNAME_SXF = "Biao_ShouxuData";

        private static string INI_HUANPIAO_ZJ_KEHUANPIAO = "KHP_COUNT";

        private static string INI_HUANPIAO_DBCLOUMNAME_ID = "Biao_Id";
        private static string INI_HUANPIAO_DBCLOUMNAME_STATUS = "Biao_Status";

        private static string INI_HUANPIAO_RET_PICIHAO = "Biao_HuanpiaoData";
        private static string INI_HUANPIAO_RET_TIME = "Biao_HuanpiaoTime";

        private const int MAX_TS_COUNT = 200;
        //------------------------------------------------------------

        #region //新手机接口==================================================

        //手机多个运单代收货款换票
        public static ComThriftMsg Phone_DaiShouHuanAllNew(string msg)
        {
            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            try
            {
                #region //反序列化

                byte[] bytrcv = Convert.FromBase64String(msg);
                ComThriftMsg comrcv = CommonTools.ByteTOComThriftAESD_Decr(bytrcv);

                if (!comrcv.__isset.struct_sqlinfo)
                {
                    ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                    return ret;
                }
                else
                {
                    if (!(comrcv.Struct_sqlinfo.__isset.string_sqlip && comrcv.Struct_sqlinfo.__isset.string_sqlname && comrcv.Struct_sqlinfo.__isset.string_sqlport
                        && comrcv.Struct_sqlinfo.__isset.string_sqlpwd && comrcv.Struct_sqlinfo.__isset.string_sqluser && comrcv.Struct_sqlinfo.__isset.string_useridkey))
                    {
                        ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                        return ret;
                    }
                }

                if (!comrcv.__isset.map_Args)
                {
                    ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                    return ret;
                }
                else
                {
                    if (!comrcv.Map_Args.Keys.Contains(INI_HUANPIAO_DBCLOUMNAME_SXF) || !comrcv.Map_Args.Keys.Contains("Contorl_Shoukuanren")
                        || !comrcv.Map_Args.Keys.Contains("Contorl_Shoukuanrenphone") || !comrcv.Map_Args.Keys.Contains("Contorl_Bankname")
                        || !comrcv.Map_Args.Keys.Contains("Contorl_Bankaccount") || !comrcv.Map_Args.Keys.Contains("Contorl_Bank"))
                    {
                        ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                        return ret;
                    }
                }

                if (!comrcv.__isset.maplist_MapArgs)
                {
                    ret.Map_Args["ErrorMsg"] = "无换票单号信息,实际换票0票";  //无换票单号信息,直接返回
                    ret.Byte_Flag = (sbyte)0;
                    return ret;
                }
                else
                {
                    if (!comrcv.Maplist_MapArgs.Keys.Contains(KEHUANPIAO_ALL_KEY) || !comrcv.Maplist_MapArgs.Keys.Contains(KEHUANPIAO_ID_KEY)
                         || !comrcv.Maplist_MapArgs.Keys.Contains(INI_HUANPIAO_SETTING) || !comrcv.Maplist_MapArgs.Keys.Contains(INI_HUANPIAO_SETTING_OUTER))
                    {
                        ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                        return ret;
                    }
                    else
                    {
                        if (comrcv.Maplist_MapArgs[KEHUANPIAO_ID_KEY].Count == 0)
                        {
                            ret.Map_Args["ErrorMsg"] = "无换票单号信息,实际换票0票";  //无可换票单号信息,直接返回
                            ret.Byte_Flag = (sbyte)0;
                            return ret;
                        }
                    }
                }


                #endregion

                #region //效验IDkey

                DataRow dr_loginfo = CheckNetIdkey(comrcv.Struct_sqlinfo);
                if (dr_loginfo == null)
                {
                    ret.Byte_Flag = (sbyte)-2;
                    ret.Map_Args["ErrorMsg"] = "IDKey无效";
                    return ret;
                }

                #endregion

                #region //生成数据量连接信息

                MySqlHelperEx mysqlhelperexImpl = new MySqlHelperEx();
                mysqlhelperexImpl.DB_CharacterSet = "utf8";

                mysqlhelperexImpl.DB_Server = comrcv.Struct_sqlinfo.String_sqlip;
                mysqlhelperexImpl.DB_Database = comrcv.Struct_sqlinfo.String_sqlname;
                mysqlhelperexImpl.DB_Port = comrcv.Struct_sqlinfo.String_sqlport;
                mysqlhelperexImpl.DB_UserID = comrcv.Struct_sqlinfo.String_sqluser;
                //mysqlhelperexImpl.DB_Password = comrcv.Struct_sqlinfo.String_sqlpwd;
                mysqlhelperexImpl.DB_Password = MySqlPwd;

                #endregion

                #region //从数据库获取信息

                try
                {
                    using (TransactionScope ts = new TransactionScope())
                    {
                        using (MySqlConnection con = new MySqlConnection(mysqlhelperexImpl.GetConnectStr()))
                        {
                            con.Open();

                            #region 从数据库查询出结果

                            List<string> allQueryBiaoIds = new List<string>();
                            //组装查询条件
                            bool befirst = true;
                            string condition = "(";
                            foreach (Dictionary<string, string> mapImpl in comrcv.Maplist_MapArgs[KEHUANPIAO_ID_KEY])
                            {
                                foreach (string id in mapImpl.Keys)
                                {
                                    if (!befirst)
                                    {
                                        condition += ",";
                                    }
                                    else
                                    {
                                        befirst = false;
                                    }
                                    condition += "'" + id + "'";
                                    allQueryBiaoIds.Add(id);
                                }
                            }
                            condition += ")";

                            //获取换票权限对应条件
                            string commandText = string.Format("SELECT Daishoulineaccount FROM {0} WHERE Account = ?netAcc AND Fuser = ?companyAcc;"
                                , dr_loginfo["Log_companyaccount"].ToString() + DOWNUSERBIAONAME);
                            MySqlParameter[] msqlp = new MySqlParameter[2];
                            msqlp[0] = new MySqlParameter("?netAcc", dr_loginfo["Log_netaccount"].ToString());
                            msqlp[1] = new MySqlParameter("?companyAcc", dr_loginfo["Log_companyaccount"].ToString());

                            object obj_downuser = mysqlhelperexImpl.ExecuteScalar(con, commandText, msqlp);
                            if (obj_downuser == null)
                            {
                                ret.Map_Args["ErrorMsg"] = "公司或网点账号不存在";
                                return ret;
                            }

                            string daishouLineAcc = Convert.ToString(obj_downuser);
                            string[] netSeq = daishouLineAcc.Split(';');
                            string conditionNet = "(";
                            conditionNet += "'" + dr_loginfo["Log_netaccount"].ToString() + "'";
                            foreach (string net in netSeq)
                            {
                                if (net.Length != 0)
                                {
                                    conditionNet += ",'" + net + "'";
                                }
                            }
                            conditionNet += ")";


                            //从正常代收表查询信息
                            commandText = string.Format("SELECT Biao_Status,Biao_Id,Biao_Number,Biao_Sender,Biao_Fromer,Biao_Goodsname,Biao_YushouData,Biao_ShishouData"
                                 + " FROM  {0} WHERE Biao_Createaccount IN {1} AND Biao_Id IN {2} ;"
                                 , dr_loginfo["Log_companyaccount"].ToString() + DAISHOUBIAONAME, conditionNet, condition);

                            DataSet ds_daishou_qxok = mysqlhelperexImpl.ExecuteDataset(con, commandText);

                            //从正常代收表查询所有信息
                            commandText = string.Format("SELECT Biao_Status,Biao_Id,Biao_Number,Biao_Sender,Biao_Fromer,Biao_Goodsname,Biao_YushouData,Biao_ShishouData"
                                 + " FROM  {0} WHERE Biao_Id IN {1} ;"
                                 , dr_loginfo["Log_companyaccount"].ToString() + DAISHOUBIAONAME, condition);

                            DataSet ds_daishou = mysqlhelperexImpl.ExecuteDataset(con, commandText);

                            //从正常代收表查询信息
                            /*commandText = string.Format("SELECT Biao_Status,Biao_Id,Biao_Number,Biao_Sender,Biao_Fromer,Biao_Goodsname,Biao_YushouData,Biao_ShishouData"
                                 + " FROM  {0} WHERE Biao_Createaccount = ?netAcc AND Biao_Id IN {1} ;"
                                 , dr_loginfo["Log_companyaccount"].ToString() + DAISHOUBIAONAME, condition);
                            msqlp = new MySqlParameter[1];
                            msqlp[0] = new MySqlParameter("?netAcc", dr_loginfo["Log_netaccount"].ToString());

                            DataSet ds_daishou = mysqlhelperexImpl.ExecuteDataset(con, commandText, msqlp);*/

                            //从正常代收中查询是否存在重票
                            commandText = string.Format("SELECT Biao_Id"
                                 + " FROM  {0} WHERE Biao_Id IN {1} ;"
                                 , dr_loginfo["Log_companyaccount"].ToString() + DAISHOUBIAONAME, condition);

                            DataSet ds_daishou_cp = mysqlhelperexImpl.ExecuteDataset(con, commandText);

                            //从已删除和挂失代收表查询信息
                            commandText = string.Format("SELECT Biao_Status,Biao_Id,Biao_Number,Biao_Sender,Biao_Fromer,Biao_Goodsname,Biao_YushouData,Biao_ShishouData"
                                 + " FROM  {0} WHERE Biao_Createaccount IN {1} AND Biao_Id IN {2} ;"
                                 , dr_loginfo["Log_companyaccount"].ToString() + GUASHIDAISHOUBIAONAME, conditionNet, condition);

                            DataSet ds_dldaishou = mysqlhelperexImpl.ExecuteDataset(con, commandText);

                            //从已完结代收表查询信息
                            commandText = string.Format("SELECT Biao_Status,Biao_Id,Biao_Number,Biao_Sender,Biao_Fromer,Biao_Goodsname,Biao_YushouData,Biao_ShishouData"
                                 + " FROM  {0} WHERE Biao_Createaccount IN {1} AND Biao_Id IN {2} ;"
                                 , dr_loginfo["Log_companyaccount"].ToString() + OVERDAISHOUBIAONAME, conditionNet, condition);

                            DataSet ds_overdaishou = mysqlhelperexImpl.ExecuteDataset(con, commandText);

                            #endregion

                            #region LINQ处理

                            //正常代收表中Biao_Id
                            var ids_of_ds_raw = from nqdr in ds_daishou.Tables[0].AsEnumerable()
                                                select nqdr.Field<string>("Biao_Id");
                            //判断正常代收表中是否存在重票
                            var ids_of_dscpall = from nqdr in ds_daishou_cp.Tables[0].AsEnumerable()
                                                 select nqdr.Field<string>("Biao_Id");
                            var ids_of_ds_group = from ids_ds in ids_of_dscpall
                                                  group ids_ds by ids_ds into group_ds
                                                  select group_ds;
                            var ids_of_ds_cp = from idsgp in ids_of_ds_group
                                               where idsgp.Count() > 1
                                               select idsgp.Key;

                            //排除重票后的正常代收表中Biao_Id
                            var ids_of_ds = ids_of_ds_raw.Except(ids_of_ds_cp);

                            /*if (ids_of_ds_cp.Count() > 0)
                            {
                                bool needadd = false;
                                string str_cp = "";
                                foreach (var cp in ids_of_ds_cp)
                                {
                                    if (needadd)
                                    {
                                        str_cp += ",";
                                    }
                                    str_cp += string.Format("<{0}>",cp);
                                    needadd = true;
                                }
                                ret.Map_Args["ErrorMsg"] = string.Format("运单{0}存在重票!不能进行换票操作!", str_cp);
                                return ret;
                            }*/

                            //挂失和删除代收表中Biao_Id
                            var ids_of_dlds_raw = from dqdr in ds_dldaishou.Tables[0].AsEnumerable()
                                                  select dqdr.Field<string>("Biao_Id");
                            var ids_of_dlds = ids_of_dlds_raw.Except(ids_of_ds_cp);

                            //完结代收表中Biao_Id
                            var ids_of_ods_raw = from oqdr in ds_overdaishou.Tables[0].AsEnumerable()
                                                 select oqdr.Field<string>("Biao_Id");
                            var ids_of_ods = ids_of_ods_raw.Except(ids_of_ds_cp);

                            //正常代收表中排除已挂失、删除和完结后的Biao_Id
                            var ids_of_ds_dis_di_o = ids_of_ds.Except(ids_of_dlds).Except(ids_of_ods);

                            //所有数据库中不能查出的Biao_Id
                            var ids_of_dball = ids_of_ds.Concat(ids_of_dlds).Concat(ids_of_ods).Distinct();
                            var ids_of_query = allQueryBiaoIds.Except(ids_of_ds_cp).Except(ids_of_dball);

                            //挂失和删除代收表中排除已完结后的Biao_Id
                            var ids_of_dlds_dis_o = ids_of_dlds.Except(ids_of_ods);

                            //正常代收表
                            var dataset_ds = from nqdr in ds_daishou.Tables[0].AsEnumerable()
                                             join id in ids_of_ds_dis_di_o
                                             on nqdr.Field<string>("Biao_Id") equals id
                                             select nqdr;

                            //正常代收表有权限
                            var dataset_ds_qxok = from nqdr in ds_daishou_qxok.Tables[0].AsEnumerable()
                                                  join id in ids_of_ds_dis_di_o
                                                  on nqdr.Field<string>("Biao_Id") equals id
                                                  select nqdr;

                            //挂失和删除代收表
                            var dataset_ds_dl = from dqdr in ds_dldaishou.Tables[0].AsEnumerable()
                                                join id in ids_of_dlds_dis_o
                                                on dqdr.Field<string>("Biao_Id") equals id
                                                select dqdr;

                            //完结代收表
                            var dataset_ds_o = from oqdr in ds_overdaishou.Tables[0].AsEnumerable()
                                               select oqdr;
                            //合并所有代收表
                            var ids_of_ds_allnet = from dqdr in dataset_ds
                                                   select dqdr.Field<string>("Biao_Id");
                            var ids_of_ds_qxnet = from dqdr in dataset_ds_qxok
                                                  select dqdr.Field<string>("Biao_Id");
                            var ids_of_ds_qxnotok = ids_of_ds_allnet.Except(ids_of_ds_qxnet);

                            //正常代收表中无权限的
                            var dataset_ds_qxnotok = from nqdr in ds_daishou.Tables[0].AsEnumerable()
                                                     join id in ids_of_ds_qxnotok
                                                     on nqdr.Field<string>("Biao_Id") equals id
                                                     select nqdr;

                            var dataset_all = dataset_ds_qxok.Concat(dataset_ds_dl).Concat(dataset_ds_o);

                            //按代收款状态排序后再按单号升序排序所有代收表
                            var dataset_all_orderded = from one in dataset_all
                                                       orderby one.Field<string>("Biao_Status"), one.Field<string>("Biao_Id") ascending
                                                       select one;

                            var dataset_all_orderded_qxnotok = from one in dataset_ds_qxnotok
                                                               orderby one.Field<string>("Biao_Status"), one.Field<string>("Biao_Id") ascending
                                                               select one;

                            var dataset_all_kehuanpiao = from one in dataset_ds_qxok
                                                         where one.Field<string>("Biao_Status") == KEHUANPIAO_STATUS
                                                         select one;
                            //此时可换票id和cookie里可换票id对比
                            var ids_of_kehuanpiao_changed = allQueryBiaoIds.Except(ids_of_ds_qxnet);
                            #endregion

                            #region 检查可换票状态是否一致
                            bool isKehuanpiaoCountMatch = false;
                            bool isStatusMatch = false;
                            if (ids_of_kehuanpiao_changed.Count() == 0 && dataset_all_kehuanpiao.Count() != 0)
                            {
                                isKehuanpiaoCountMatch = true;
                            }

                            string PathStr = "D://CompanyConfig//" + dr_loginfo["Log_companyaccount"].ToString() + "//SettingDir//CaiWuSetting.ini";
                            csIniFiles CIni = new csIniFiles(PathStr);
                            string typeStr = CIni.ReadString(INI_HUANPIAO_SETTING, INI_HUANPIAO_SETTING_TYPE, "");
                            string dbzStr = CIni.ReadString(INI_HUANPIAO_SETTING, INI_HUANPIAO_SETTING_DBZ, "");
                            string dbmStr = CIni.ReadString(INI_HUANPIAO_SETTING, INI_HUANPIAO_SETTING_DBM, "");
                            string hbzStr = CIni.ReadString(INI_HUANPIAO_SETTING, INI_HUANPIAO_SETTING_HBZ, "");
                            string hbmStr = CIni.ReadString(INI_HUANPIAO_SETTING, INI_HUANPIAO_SETTING_HBM, "");
                            string pjStr = CIni.ReadString(INI_HUANPIAO_SETTING, INI_HUANPIAO_SETTING_PJ, "");

                            //1.检查id是否有数据库里不能查到的或者被删除或挂失的
                            if (isKehuanpiaoCountMatch && ids_of_query.Count() == 0)
                            {
                                //2.检查财务配置信息是否改变
                                /*string PathStr = "D://CompanyConfig//" + dr_loginfo["Log_companyaccount"].ToString() + "//SettingDir//CaiWuSetting.ini";
                                csIniFiles CIni = new csIniFiles(PathStr);
                                string typeStr = CIni.ReadString(INI_HUANPIAO_SETTING, INI_HUANPIAO_SETTING_TYPE, "");
                                string dbzStr = CIni.ReadString(INI_HUANPIAO_SETTING, INI_HUANPIAO_SETTING_DBZ, "");
                                string dbmStr = CIni.ReadString(INI_HUANPIAO_SETTING, INI_HUANPIAO_SETTING_DBM, "");
                                string hbzStr = CIni.ReadString(INI_HUANPIAO_SETTING, INI_HUANPIAO_SETTING_HBZ, "");
                                string hbmStr = CIni.ReadString(INI_HUANPIAO_SETTING, INI_HUANPIAO_SETTING_HBM, "");
                                string pjStr = CIni.ReadString(INI_HUANPIAO_SETTING, INI_HUANPIAO_SETTING_PJ, "");*/
                                if (typeStr == comrcv.Maplist_MapArgs[INI_HUANPIAO_SETTING].First()[INI_HUANPIAO_SETTING_TYPE])
                                {
                                    if (typeStr == INI_HUANPIAO_SETTING_TYPE_DB)
                                    {
                                        isStatusMatch = (dbzStr == comrcv.Maplist_MapArgs[INI_HUANPIAO_SETTING].First()[INI_HUANPIAO_SETTING_DBZ]);
                                        isStatusMatch = isStatusMatch && (dbmStr == comrcv.Maplist_MapArgs[INI_HUANPIAO_SETTING].First()[INI_HUANPIAO_SETTING_DBM]);
                                    }
                                    else if (typeStr == INI_HUANPIAO_SETTING_TYPE_HB)
                                    {
                                        isStatusMatch = (hbzStr == comrcv.Maplist_MapArgs[INI_HUANPIAO_SETTING].First()[INI_HUANPIAO_SETTING_HBZ]);
                                        isStatusMatch = isStatusMatch && (hbmStr == comrcv.Maplist_MapArgs[INI_HUANPIAO_SETTING].First()[INI_HUANPIAO_SETTING_HBM]);
                                    }
                                    else if (typeStr == INI_HUANPIAO_SETTING_TYPE_HZ)
                                    {
                                        isStatusMatch = (pjStr == comrcv.Maplist_MapArgs[INI_HUANPIAO_SETTING].First()[INI_HUANPIAO_SETTING_PJ]);
                                    }
                                    if (isStatusMatch)
                                    {
                                        //3.检查所有可换票单关键信息是否改变
                                        var query_dif = from oldids in comrcv.Maplist_MapArgs[KEHUANPIAO_ALL_KEY]
                                                        from nowids in dataset_all_kehuanpiao
                                                        where (oldids[INI_HUANPIAO_DBCLOUMNAME_ID] == nowids.Field<string>(INI_HUANPIAO_DBCLOUMNAME_ID).ToString())
                                                        && ((oldids[INI_HUANPIAO_DBCLOUMNAME_STATUS] != nowids.Field<string>(INI_HUANPIAO_DBCLOUMNAME_STATUS).ToString())
                                                        || (oldids[INI_HUANPIAO_DBCLOUMNAME_SS] != nowids.Field<string>(INI_HUANPIAO_DBCLOUMNAME_SS).ToString()))
                                                        select oldids[INI_HUANPIAO_DBCLOUMNAME_ID];

                                        isStatusMatch = (query_dif.Count() == 0);
                                    }
                                }
                            }
                            #endregion

                            if (isKehuanpiaoCountMatch && isStatusMatch)
                            {
                                #region 组装返回_可换票状态一致_可进行换票

                                string huanLogId = "";
                                string huanLogTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

                                #region 获取代收换票批号
                                commandText = string.Format("SELECT Shortname,Huancount"
                                     + " FROM  {0} WHERE Account = ?netAcc AND Fuser = ?companyAcc;"
                                     , dr_loginfo["Log_companyaccount"].ToString() + DOWNUSERBIAONAME);
                                msqlp = new MySqlParameter[2];
                                msqlp[0] = new MySqlParameter("?netAcc", dr_loginfo["Log_netaccount"].ToString());
                                msqlp[1] = new MySqlParameter("?companyAcc", dr_loginfo["Log_companyaccount"].ToString());

                                DataRow huan_dr = mysqlhelperexImpl.ExecuteDataRow(con, commandText, msqlp);
                                if (huan_dr != null)
                                {
                                    string nowdate = DateTime.Now.ToString("yyyyMMdd");
                                    string shortname = huan_dr["Shortname"].ToString();
                                    string oldid = huan_dr["Huancount"].ToString();
                                    Int32 huancount = 1;
                                    try
                                    {
                                        if (oldid.Substring(0, 8) == nowdate)
                                        {
                                            huancount = Convert.ToInt32(oldid.Remove(0, 8));
                                            huancount++;
                                        }
                                    }
                                    catch
                                    {

                                    }
                                    huanLogId = shortname + "换" + nowdate + huancount.ToString();

                                    commandText = string.Format("UPDATE {0} set Huancount = ?huanAcc WHERE Account = ?netAcc;"
                                     , dr_loginfo["Log_companyaccount"].ToString() + DOWNUSERBIAONAME);
                                    msqlp = new MySqlParameter[2];
                                    msqlp[0] = new MySqlParameter("?huanAcc", nowdate + huancount.ToString());
                                    msqlp[1] = new MySqlParameter("?netAcc", dr_loginfo["Log_netaccount"].ToString());

                                    int update_rt = mysqlhelperexImpl.ExecuteNonQuery(con, commandText, msqlp);
                                    if (update_rt != 1)
                                    {
                                        ret.Map_Args["ErrorMsg"] = "更新换票批次号错误";  //参数错误
                                        return ret;
                                    }
                                }
                                else
                                {
                                    ret.Map_Args["ErrorMsg"] = "换票批次号错误";  //参数错误
                                    return ret;
                                }
                                #endregion

                                #region 增加打款数据表记录

                                Int64 coustSJYF = Convert.ToInt64(comrcv.Maplist_MapArgs[INI_HUANPIAO_SETTING_OUTER].First()[INI_HUANPIAO_DBCLOUMNAME_SS]) - Convert.ToInt64(comrcv.Map_Args[INI_HUANPIAO_DBCLOUMNAME_SXF]);

                                commandText = string.Format("INSERT INTO {0} VALUES (null, " +
                                    " ?cnetAcc, ?cnetName, ?cTime, ?cCount, ?cDkr, ?cDkrp, ?cSkr, ?cSkrp, ?cBK_Skr, ?cBK_Skcount," +
                                    " ?cBkname, ?cAllcost, ?cAllSXF, ?cAll_IDs, ?cType, ?cStatus, ?cWorker, ?cWorkerp, ?cDefault);"
                                    , dr_loginfo["Log_companyaccount"].ToString() + DAKUANRECORDBIAONAME);
                                msqlp = new MySqlParameter[19];
                                msqlp[0] = new MySqlParameter("?cnetAcc", dr_loginfo["Log_netaccount"].ToString());
                                msqlp[1] = new MySqlParameter("?cnetName", dr_loginfo["Log_netname"].ToString());
                                msqlp[2] = new MySqlParameter("?cTime", huanLogTime);
                                msqlp[3] = new MySqlParameter("?cCount", huanLogId);
                                msqlp[4] = new MySqlParameter("?cDkr", "");
                                msqlp[5] = new MySqlParameter("?cDkrp", "");
                                msqlp[6] = new MySqlParameter("?cSkr", comrcv.Map_Args["Contorl_Shoukuanren"]);
                                msqlp[7] = new MySqlParameter("?cSkrp", comrcv.Map_Args["Contorl_Shoukuanrenphone"]);
                                msqlp[8] = new MySqlParameter("?cBK_Skr", comrcv.Map_Args["Contorl_Bankname"]);
                                msqlp[9] = new MySqlParameter("?cBK_Skcount", comrcv.Map_Args["Contorl_Bankaccount"]);
                                msqlp[10] = new MySqlParameter("?cBkname", comrcv.Map_Args["Contorl_Bank"]);
                                //msqlp[11] = new MySqlParameter("?cAllcost", comrcv.Maplist_MapArgs[INI_HUANPIAO_SETTING_OUTER].First()[INI_HUANPIAO_DBCLOUMNAME_SS]);
                                msqlp[11] = new MySqlParameter("?cAllcost", coustSJYF.ToString());
                                msqlp[12] = new MySqlParameter("?cAllSXF", comrcv.Map_Args[INI_HUANPIAO_DBCLOUMNAME_SXF]);

                                string allidsquery = "";
                                foreach (string idsquery in allQueryBiaoIds)
                                {
                                    allidsquery += idsquery + ";";
                                }

                                msqlp[13] = new MySqlParameter("?cAll_IDs", allidsquery);
                                msqlp[14] = new MySqlParameter("?cType", "换票");
                                msqlp[15] = new MySqlParameter("?cStatus", "已换票");
                                msqlp[16] = new MySqlParameter("?cWorker", dr_loginfo["Log_ygname"].ToString());
                                msqlp[17] = new MySqlParameter("?cWorkerp", "");
                                msqlp[18] = new MySqlParameter("?cDefault", "");

                                int insert_rt = mysqlhelperexImpl.ExecuteNonQuery(con, commandText, msqlp);
                                if (insert_rt != 1)
                                {
                                    ret.Map_Args["ErrorMsg"] = "新增打款记录错误";  //参数错误
                                    return ret;
                                }

                                #endregion

                                #region 更新代收记录信息

                                Int64 total_sxf = Convert.ToInt64(comrcv.Map_Args[INI_HUANPIAO_DBCLOUMNAME_SXF]);
                                Int64 dp_sxf = 0;
                                foreach (DataRow dr in dataset_all_kehuanpiao)
                                {
                                    Int64 dp_ss = Convert.ToInt64(dr[INI_HUANPIAO_DBCLOUMNAME_SS].ToString());
                                    if (dp_ss >= total_sxf)
                                    {
                                        dp_sxf = total_sxf;
                                        total_sxf -= dp_sxf;
                                    }
                                    else
                                    {
                                        dp_sxf = dp_ss;
                                        total_sxf -= dp_sxf;
                                    }

                                    commandText = string.Format("UPDATE {0} set Biao_Status = ?biao_status, Biao_ShouxuData = ?sxf," +
                                        " Biao_ShifuData = ?sf, Biao_HuanpiaoData = ?hpdata WHERE Biao_Id = ?biaoid;"
                                        , dr_loginfo["Log_companyaccount"].ToString() + DAISHOUBIAONAME);
                                    msqlp = new MySqlParameter[5];
                                    msqlp[0] = new MySqlParameter("?biao_status", "已换票");
                                    msqlp[1] = new MySqlParameter("?sxf", dp_sxf.ToString());
                                    msqlp[2] = new MySqlParameter("?sf", (dp_ss - dp_sxf).ToString());
                                    msqlp[3] = new MySqlParameter("?hpdata", huanLogId);
                                    msqlp[4] = new MySqlParameter("?biaoid", dr[INI_HUANPIAO_DBCLOUMNAME_ID].ToString());

                                    int update_rt = mysqlhelperexImpl.ExecuteNonQuery(con, commandText, msqlp);

                                    if (update_rt < 1)
                                    {
                                        ret.Map_Args["ErrorMsg"] = "更新代收款状态记录错误";  //参数错误
                                        return ret;
                                    }
                                    else if (update_rt > 1)
                                    {
                                        ret.Map_Args["ErrorMsg"] = string.Format("运单<{0}>存在重票,不能进行换票操作!", dr[INI_HUANPIAO_DBCLOUMNAME_ID].ToString());  //重票错误
                                        return ret;
                                    }

                                    commandText = string.Format("INSERT INTO {0} VALUES (null, " +
                                    " ?netAcc, ?netName, ?biaoid, ?times, ?status, ?worker, ?machine, ?Ddefault);"
                                    , dr_loginfo["Log_companyaccount"].ToString() + LISTBIAONAME);
                                    msqlp = new MySqlParameter[8];
                                    msqlp[0] = new MySqlParameter("?netAcc", dr_loginfo["Log_netaccount"].ToString());
                                    msqlp[1] = new MySqlParameter("?netName", dr_loginfo["Log_netname"].ToString());
                                    msqlp[2] = new MySqlParameter("?biaoid", dr[INI_HUANPIAO_DBCLOUMNAME_ID].ToString());
                                    msqlp[3] = new MySqlParameter("?times", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                                    msqlp[4] = new MySqlParameter("?status", "代收换票");
                                    msqlp[5] = new MySqlParameter("?worker", dr_loginfo["Log_ygname"].ToString());
                                    msqlp[6] = new MySqlParameter("?machine", dr_loginfo["Log_device"].ToString());
                                    msqlp[7] = new MySqlParameter("?Ddefault", "");

                                    update_rt = mysqlhelperexImpl.ExecuteNonQuery(con, commandText, msqlp);
                                    if (update_rt != 1)
                                    {
                                        ret.Map_Args["ErrorMsg"] = "新增操作记录错误";  //参数错误
                                        return ret;
                                    }
                                }

                                #endregion

                                #region 增加换票批次号和换票时间到返回

                                ret.Map_Args.Add(INI_HUANPIAO_RET_PICIHAO, huanLogId);
                                ret.Map_Args.Add(INI_HUANPIAO_RET_TIME, huanLogTime);

                                #endregion

                                #endregion
                            }
                            else
                            {
                                #region 组装返回_可换票状态不一致

                                //1.检查是否所有单子均为正常可查出运单
                                DataTable dt = dt = ds_daishou.Tables[0];

                                List<Dictionary<string, string>> one_ListImpl = new List<Dictionary<string, string>>();

                                //将不存在的运单标志为不存在状态后返回
                                foreach (var id in ids_of_query)
                                {
                                    Dictionary<string, string> one_ydImpl = new Dictionary<string, string>();
                                    one_ydImpl.Add("Biao_Id", id);
                                    one_ydImpl.Add("Biao_Status", IDISNOTEXIST);
                                    one_ListImpl.Add(one_ydImpl);
                                }
                                //将重票的运单标志为重票后返回
                                foreach (var id in ids_of_ds_cp)
                                {
                                    Dictionary<string, string> one_ydImpl = new Dictionary<string, string>();
                                    one_ydImpl.Add("Biao_Id", id);
                                    one_ydImpl.Add("Biao_Status", IDISEXISTALD);
                                    one_ListImpl.Add(one_ydImpl);
                                }
                                //将排序后所有能查出的代收款返回,包括有权限和无权限的
                                foreach (DataRow dr in dataset_all_orderded_qxnotok)
                                {
                                    Dictionary<string, string> one_ydImpl = new Dictionary<string, string>();
                                    foreach (DataColumn dc in dt.Columns)
                                    {
                                        if (dc.ColumnName == "Biao_Status")
                                        {
                                            one_ydImpl.Add(dc.ColumnName, dr[dc.ColumnName].ToString() + IDIS_QXNOTOK);
                                        }
                                        else
                                        {
                                            one_ydImpl.Add(dc.ColumnName, dr[dc.ColumnName].ToString());
                                        }
                                    }
                                    one_ListImpl.Add(one_ydImpl);
                                }
                                foreach (DataRow dr in dataset_all_orderded)
                                {
                                    Dictionary<string, string> one_ydImpl = new Dictionary<string, string>();
                                    foreach (DataColumn dc in dt.Columns)
                                    {
                                        one_ydImpl.Add(dc.ColumnName, dr[dc.ColumnName].ToString());
                                    }
                                    one_ListImpl.Add(one_ydImpl);
                                }

                                ret.List_MapArgs = one_ListImpl;

                                //2.保存所有可换票单号状态、详细信息和换票配置信息，用作换票时判断状态是否已变
                                Dictionary<string, List<Dictionary<string, string>>> mapListMapImpl = new Dictionary<string, List<Dictionary<string, string>>>();
                                List<Dictionary<string, string>> listMapImpl = new List<Dictionary<string, string>>();
                                List<Dictionary<string, string>> idlistMapImpl = new List<Dictionary<string, string>>();
                                List<Dictionary<string, string>> cwsettinglistMapImpl = new List<Dictionary<string, string>>();
                                List<Dictionary<string, string>> outretlistMapImpl = new List<Dictionary<string, string>>();
                                Dictionary<string, string> outretImpl = new Dictionary<string, string>();
                                outretlistMapImpl.Add(outretImpl);
                                mapListMapImpl.Add(KEHUANPIAO_ALL_KEY, listMapImpl);
                                mapListMapImpl.Add(KEHUANPIAO_ID_KEY, idlistMapImpl);
                                mapListMapImpl.Add(INI_HUANPIAO_SETTING, cwsettinglistMapImpl);
                                mapListMapImpl.Add(INI_HUANPIAO_SETTING_OUTER, outretlistMapImpl);
                                foreach (DataRow dr in dataset_all_kehuanpiao)
                                {
                                    //可换票详细清单
                                    Dictionary<string, string> one_ydImpl = new Dictionary<string, string>();
                                    foreach (DataColumn dc in dt.Columns)
                                    {
                                        one_ydImpl.Add(dc.ColumnName, dr[dc.ColumnName].ToString());
                                    }
                                    listMapImpl.Add(one_ydImpl);
                                    //可换票Id列表，用作在确认换票时提交服务器
                                    Dictionary<string, string> idone_ydImpl = new Dictionary<string, string>();
                                    idone_ydImpl.Add(dr["Biao_Id"].ToString(), "");
                                    idlistMapImpl.Add(idone_ydImpl);
                                }
                                //换票设置信息
                                /*string PathStr = "D://CompanyConfig//" + dr_loginfo["Log_companyaccount"].ToString() + "//SettingDir//CaiWuSetting.ini";
                                csIniFiles CIni = new csIniFiles(PathStr);
                                string typeStr = CIni.ReadString(INI_HUANPIAO_SETTING, INI_HUANPIAO_SETTING_TYPE, "");
                                string dbzStr = CIni.ReadString(INI_HUANPIAO_SETTING, INI_HUANPIAO_SETTING_DBZ, "");
                                string dbmStr = CIni.ReadString(INI_HUANPIAO_SETTING, INI_HUANPIAO_SETTING_DBM, "");
                                string hbzStr = CIni.ReadString(INI_HUANPIAO_SETTING, INI_HUANPIAO_SETTING_HBZ, "");
                                string hbmStr = CIni.ReadString(INI_HUANPIAO_SETTING, INI_HUANPIAO_SETTING_HBM, "");
                                string pjStr = CIni.ReadString(INI_HUANPIAO_SETTING, INI_HUANPIAO_SETTING_PJ, "");*/
                                Dictionary<string, string> settingone_ydImpl = new Dictionary<string, string>();
                                settingone_ydImpl.Add(INI_HUANPIAO_SETTING_TYPE, typeStr);
                                settingone_ydImpl.Add(INI_HUANPIAO_SETTING_DBZ, dbzStr);
                                settingone_ydImpl.Add(INI_HUANPIAO_SETTING_DBM, dbmStr);
                                settingone_ydImpl.Add(INI_HUANPIAO_SETTING_HBZ, hbzStr);
                                settingone_ydImpl.Add(INI_HUANPIAO_SETTING_HBM, hbmStr);
                                settingone_ydImpl.Add(INI_HUANPIAO_SETTING_PJ, pjStr);
                                cwsettinglistMapImpl.Add(settingone_ydImpl);

                                //3.生成所有可换票单号手续费用等信息
                                if (typeStr == INI_HUANPIAO_SETTING_TYPE_DB)
                                {
                                    Int64 pit = 0;
                                    Int64 dj_sxf = 0;
                                    Int64 zj_ys = 0;
                                    Int64 zj_ss = 0;
                                    Int64 zj_ps = 0;
                                    Int64 zj_sxf = 0;
                                    foreach (DataRow dr in dataset_all_kehuanpiao)
                                    {
                                        zj_ys += Convert.ToInt64(dr[INI_HUANPIAO_DBCLOUMNAME_YS].ToString());
                                        zj_ss += Convert.ToInt64(dr[INI_HUANPIAO_DBCLOUMNAME_SS].ToString());
                                        pit = (Int64)(Convert.ToInt64(dr[INI_HUANPIAO_DBCLOUMNAME_SS].ToString()) / Convert.ToDouble(dbmStr));
                                        pit = (Convert.ToInt64(dr[INI_HUANPIAO_DBCLOUMNAME_SS].ToString()) > Convert.ToDouble(dbmStr) * pit) ? ++pit : pit;
                                        dj_sxf = (Int64)(Convert.ToDouble(dbzStr) * pit);
                                        zj_sxf += dj_sxf;
                                        zj_ps++;
                                    }

                                    ret.Map_Args.Add(INI_HUANPIAO_DBCLOUMNAME_YS, zj_ys.ToString());
                                    ret.Map_Args.Add(INI_HUANPIAO_DBCLOUMNAME_SS, zj_ss.ToString());
                                    ret.Map_Args.Add(INI_HUANPIAO_DBCLOUMNAME_SXF, zj_sxf.ToString());
                                    ret.Map_Args.Add(INI_HUANPIAO_ZJ_KEHUANPIAO, zj_ps.ToString());

                                    outretImpl.Add(INI_HUANPIAO_DBCLOUMNAME_YS, zj_ys.ToString());
                                    outretImpl.Add(INI_HUANPIAO_DBCLOUMNAME_SS, zj_ss.ToString());
                                    outretImpl.Add(INI_HUANPIAO_DBCLOUMNAME_SXF, zj_sxf.ToString());
                                    outretImpl.Add(INI_HUANPIAO_ZJ_KEHUANPIAO, zj_ps.ToString());
                                }
                                else if (typeStr == INI_HUANPIAO_SETTING_TYPE_HB)
                                {
                                    Int64 zj_ys = 0;
                                    Int64 zj_ss = 0;
                                    Int64 zj_ps = 0;
                                    Int64 zj_sxf = 0;
                                    foreach (DataRow dr in dataset_all_kehuanpiao)
                                    {
                                        zj_ys += Convert.ToInt64(dr[INI_HUANPIAO_DBCLOUMNAME_YS].ToString());
                                        zj_ss += Convert.ToInt64(dr[INI_HUANPIAO_DBCLOUMNAME_SS].ToString());
                                        zj_ps++;
                                    }
                                    Int64 pit = (Int64)(zj_ss / Convert.ToDouble(hbmStr));
                                    pit = (zj_ss > Convert.ToDouble(hbmStr) * pit) ? ++pit : pit;
                                    zj_sxf = (Int64)(Convert.ToDouble(hbzStr) * pit);

                                    ret.Map_Args.Add(INI_HUANPIAO_DBCLOUMNAME_YS, zj_ys.ToString());
                                    ret.Map_Args.Add(INI_HUANPIAO_DBCLOUMNAME_SS, zj_ss.ToString());
                                    ret.Map_Args.Add(INI_HUANPIAO_DBCLOUMNAME_SXF, zj_sxf.ToString());
                                    ret.Map_Args.Add(INI_HUANPIAO_ZJ_KEHUANPIAO, zj_ps.ToString());

                                    outretImpl.Add(INI_HUANPIAO_DBCLOUMNAME_YS, zj_ys.ToString());
                                    outretImpl.Add(INI_HUANPIAO_DBCLOUMNAME_SS, zj_ss.ToString());
                                    outretImpl.Add(INI_HUANPIAO_DBCLOUMNAME_SXF, zj_sxf.ToString());
                                    outretImpl.Add(INI_HUANPIAO_ZJ_KEHUANPIAO, zj_ps.ToString());
                                }
                                else if (typeStr == INI_HUANPIAO_SETTING_TYPE_HZ)
                                {
                                    Double pit = Convert.ToDouble(pjStr);
                                    Int64 zj_ys = 0;
                                    Int64 zj_ss = 0;
                                    Int64 zj_ps = 0;
                                    Double zj_sxf = 0;
                                    foreach (DataRow dr in dataset_all_kehuanpiao)
                                    {
                                        zj_ys += Convert.ToInt64(dr[INI_HUANPIAO_DBCLOUMNAME_YS].ToString());
                                        zj_ss += Convert.ToInt64(dr[INI_HUANPIAO_DBCLOUMNAME_SS].ToString());
                                        zj_sxf += pit;
                                        zj_ps++;
                                    }

                                    ret.Map_Args.Add(INI_HUANPIAO_DBCLOUMNAME_YS, zj_ys.ToString());
                                    ret.Map_Args.Add(INI_HUANPIAO_DBCLOUMNAME_SS, zj_ss.ToString());
                                    ret.Map_Args.Add(INI_HUANPIAO_DBCLOUMNAME_SXF, ((Int64)zj_sxf).ToString());
                                    ret.Map_Args.Add(INI_HUANPIAO_ZJ_KEHUANPIAO, zj_ps.ToString());

                                    outretImpl.Add(INI_HUANPIAO_DBCLOUMNAME_YS, zj_ys.ToString());
                                    outretImpl.Add(INI_HUANPIAO_DBCLOUMNAME_SS, zj_ss.ToString());
                                    outretImpl.Add(INI_HUANPIAO_DBCLOUMNAME_SXF, ((Int64)zj_sxf).ToString());
                                    outretImpl.Add(INI_HUANPIAO_ZJ_KEHUANPIAO, zj_ps.ToString());
                                }
                                else
                                {
                                    ret.Map_Args["ErrorMsg"] = "换票财务设置错误";
                                    return ret;
                                }

                                ret.Maplist_MapArgs = mapListMapImpl;
                                if (isKehuanpiaoCountMatch)
                                {
                                    ret.Map_Args["ErrorMsg"] = "换票确认前后状态不一致,请重新换票";
                                }
                                else
                                {
                                    ret.Map_Args["ErrorMsg"] = "可换票信息已经改变,请重新查询后换票";
                                }

                                return ret;

                                #endregion
                            }

                            con.Close();
                        }

                        ts.Complete();
                    }
                }
                catch (System.Exception e)
                {
                    ret.Map_Args["ErrorMsg"] = e.Message;
                    return ret;
                }

                #endregion

                #region //组装返回值

                ret.Map_Args["ErrorMsg"] = "";
                ret.Byte_Flag = (sbyte)0;  //正常有效返回

                #endregion

            }
            catch (System.Exception e)
            {
                ret.Map_Args["ErrorMsg"] = e.Message;
                return ret;
            }

            return ret;
        }

        //手机拉取运单代收信息
        public static ComThriftMsg Phone_GetDaiShouProNew(string msg)
        {
            ILog logRecode = LogManager.GetLogger("LoggerHuan");
            logRecode.Info("=============");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            try
            {
                #region //反序列化

                byte[] bytrcv = Convert.FromBase64String(msg);
                ComThriftMsg comrcv = CommonTools.ByteTOComThriftAESD(bytrcv);

                if (!comrcv.__isset.struct_sqlinfo)
                {
                    ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                    return ret;
                }
                else
                {
                    if (!(comrcv.Struct_sqlinfo.__isset.string_sqlip && comrcv.Struct_sqlinfo.__isset.string_sqlname && comrcv.Struct_sqlinfo.__isset.string_sqlport
                        && comrcv.Struct_sqlinfo.__isset.string_sqlpwd && comrcv.Struct_sqlinfo.__isset.string_sqluser && comrcv.Struct_sqlinfo.__isset.string_useridkey))
                    {
                        ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                        return ret;
                    }
                }

                if (!comrcv.__isset.list_MapArgs)
                {
                    ret.Map_Args["ErrorMsg"] = "无查询单号信息,直接返回";  //无查询单号信息,直接返回
                    ret.Byte_Flag = (sbyte)-1;
                    return ret;
                }
                else
                {
                    if (comrcv.List_MapArgs.Count == 0)
                    {
                        ret.Map_Args["ErrorMsg"] = "无查询单号信息,直接返回";  //无查询单号信息,直接返回
                        ret.Byte_Flag = (sbyte)-1;
                        return ret;
                    }
                }
                #endregion

                #region //效验IDkey

                DataRow dr_loginfo = CheckNetIdkey(comrcv.Struct_sqlinfo);
                if (dr_loginfo == null)
                {
                    ret.Byte_Flag = (sbyte)-2;
                    ret.Map_Args["ErrorMsg"] = "IDKey无效";
                    return ret;
                }

                #endregion
                ILog logJieKou = LogManager.GetLogger("LoggerJieKou");
                logJieKou.Info("手机拉取运单代收信息" + "-" + dr_loginfo["Log_companyname"].ToString() + "-" + dr_loginfo["Log_netname"].ToString());
                #region //生成数据量连接信息

                MySqlHelperEx mysqlhelperexImpl = new MySqlHelperEx();
                mysqlhelperexImpl.DB_CharacterSet = "utf8";

                mysqlhelperexImpl.DB_Server = comrcv.Struct_sqlinfo.String_sqlip;
                mysqlhelperexImpl.DB_Database = comrcv.Struct_sqlinfo.String_sqlname;
                mysqlhelperexImpl.DB_Port = comrcv.Struct_sqlinfo.String_sqlport;
                mysqlhelperexImpl.DB_UserID = comrcv.Struct_sqlinfo.String_sqluser;
                //mysqlhelperexImpl.DB_Password = comrcv.Struct_sqlinfo.String_sqlpwd;
                mysqlhelperexImpl.DB_Password = MySqlPwd;

                #endregion

                #region //从数据库获取信息

                try
                {
                    using (TransactionScope ts = new TransactionScope())
                    {
                        using (MySqlConnection con = new MySqlConnection(mysqlhelperexImpl.GetConnectStr()))
                        {
                            con.Open();

                            #region 从数据库查询出结果

                            List<string> allQueryBiaoIds = new List<string>();
                            //组装查询条件
                            bool befirst = true;
                            string condition = "(";
                            foreach (Dictionary<string, string> mapImpl in comrcv.List_MapArgs)
                            {
                                foreach (string id in mapImpl.Keys)
                                {
                                    if (!befirst)
                                    {
                                        condition += ",";
                                    }
                                    else
                                    {
                                        befirst = false;
                                    }
                                    condition += "'" + id + "'";
                                    allQueryBiaoIds.Add(id);
                                }
                            }
                            condition += ")";

                            //获取换票权限对应条件
                            string commandText = string.Format("SELECT Daishoulineaccount FROM {0} WHERE Account = ?netAcc AND Fuser = ?companyAcc;"
                                , dr_loginfo["Log_companyaccount"].ToString() + DOWNUSERBIAONAME);
                            MySqlParameter[] msqlp = new MySqlParameter[2];
                            msqlp[0] = new MySqlParameter("?netAcc", dr_loginfo["Log_netaccount"].ToString());
                            msqlp[1] = new MySqlParameter("?companyAcc", dr_loginfo["Log_companyaccount"].ToString());

                            object obj_downuser = mysqlhelperexImpl.ExecuteScalar(con, commandText, msqlp);
                            if (obj_downuser == null)
                            {
                                ret.Map_Args["ErrorMsg"] = "公司或网点账号不存在";
                                return ret;
                            }

                            string daishouLineAcc = Convert.ToString(obj_downuser);
                            string[] netSeq = daishouLineAcc.Split(';');
                            string conditionNet = "(";
                            conditionNet += "'" + dr_loginfo["Log_netaccount"].ToString() + "'";
                            foreach (string net in netSeq)
                            {
                                if (net.Length != 0)
                                {
                                    conditionNet += ",'" + net + "'";
                                }
                            }
                            conditionNet += ")";


                            //从正常代收表查询信息
                            commandText = string.Format("SELECT Biao_Status,Biao_Id,Biao_Number,Biao_Sender,Biao_Fromer,Biao_Goodsname,Biao_YushouData,Biao_ShishouData,Biao_Default"
                                 + " FROM  {0} WHERE Biao_Createaccount IN {1} AND Biao_Id IN {2} ;"
                                 , dr_loginfo["Log_companyaccount"].ToString() + DAISHOUBIAONAME, conditionNet, condition);

                            logRecode.Info("1== " + commandText);

                            DataSet ds_daishou_qxok = mysqlhelperexImpl.ExecuteDataset(con, commandText);

                            //从正常代收表查询所有信息
                            commandText = string.Format("SELECT Biao_Status,Biao_Id,Biao_Number,Biao_Sender,Biao_Fromer,Biao_Goodsname,Biao_YushouData,Biao_ShishouData,Biao_Default"
                                 + " FROM  {0} WHERE Biao_Id IN {1} ;"
                                 , dr_loginfo["Log_companyaccount"].ToString() + DAISHOUBIAONAME, condition);

                            logRecode.Info("2== " + commandText);

                            DataSet ds_daishou = mysqlhelperexImpl.ExecuteDataset(con, commandText);

                            //从正常代收表查询信息
                            /*commandText = string.Format("SELECT Biao_Status,Biao_Id,Biao_Number,Biao_Sender,Biao_Fromer,Biao_Goodsname,Biao_YushouData,Biao_ShishouData"
                                 + " FROM  {0} WHERE Biao_Createaccount = ?netAcc AND Biao_Id IN {1} ;"
                                 , dr_loginfo["Log_companyaccount"].ToString() + DAISHOUBIAONAME, condition);
                            msqlp = new MySqlParameter[1];
                            msqlp[0] = new MySqlParameter("?netAcc", dr_loginfo["Log_netaccount"].ToString());

                            DataSet ds_daishou = mysqlhelperexImpl.ExecuteDataset(con, commandText, msqlp);*/

                            //从正常代收中查询是否存在重票
                            commandText = string.Format("SELECT Biao_Id"
                                 + " FROM  {0} WHERE Biao_Id IN {1} ;"
                                 , dr_loginfo["Log_companyaccount"].ToString() + DAISHOUBIAONAME, condition);

                            DataSet ds_daishou_cp = mysqlhelperexImpl.ExecuteDataset(con, commandText);

                            //从已删除和挂失代收表查询信息
                            commandText = string.Format("SELECT Biao_Status,Biao_Id,Biao_Number,Biao_Sender,Biao_Fromer,Biao_Goodsname,Biao_YushouData,Biao_ShishouData,Biao_Default"
                                 + " FROM  {0} WHERE Biao_Createaccount IN {1} AND Biao_Id IN {2} ;"
                                 , dr_loginfo["Log_companyaccount"].ToString() + GUASHIDAISHOUBIAONAME, conditionNet, condition);

                            logRecode.Info("3== " + commandText);

                            DataSet ds_dldaishou = mysqlhelperexImpl.ExecuteDataset(con, commandText);

                            //从已完结代收表查询信息
                            commandText = string.Format("SELECT Biao_Status,Biao_Id,Biao_Number,Biao_Sender,Biao_Fromer,Biao_Goodsname,Biao_YushouData,Biao_ShishouData,Biao_Default"
                                 + " FROM  {0} WHERE Biao_Createaccount IN {1} AND Biao_Id IN {2} ;"
                                 , dr_loginfo["Log_companyaccount"].ToString() + OVERDAISHOUBIAONAME, conditionNet, condition);

                            logRecode.Info("4== " + commandText);

                            DataSet ds_overdaishou = mysqlhelperexImpl.ExecuteDataset(con, commandText);

                            #endregion

                            #region LINQ处理

                            //正常代收表中Biao_Id
                            var ids_of_ds_raw = from nqdr in ds_daishou.Tables[0].AsEnumerable()
                                                select nqdr.Field<string>("Biao_Id");
                            //判断正常代收表中是否存在重票
                            var ids_of_dscpall = from nqdr in ds_daishou_cp.Tables[0].AsEnumerable()
                                                 select nqdr.Field<string>("Biao_Id");
                            var ids_of_ds_group = from ids_ds in ids_of_dscpall
                                                  group ids_ds by ids_ds into group_ds
                                                  select group_ds;
                            var ids_of_ds_cp = from idsgp in ids_of_ds_group
                                               where idsgp.Count() > 1
                                               select idsgp.Key;

                            //排除重票后的正常代收表中Biao_Id
                            var ids_of_ds = ids_of_ds_raw.Except(ids_of_ds_cp);

                            /*if (ids_of_ds_cp.Count() > 0)
                            {
                                bool needadd = false;
                                string str_cp = "";
                                foreach (var cp in ids_of_ds_cp)
                                {
                                    if (needadd)
                                    {
                                        str_cp += ",";
                                    }
                                    str_cp += string.Format("<{0}>",cp);
                                    needadd = true;
                                }
                                ret.Map_Args["ErrorMsg"] = string.Format("运单{0}存在重票!不能进行换票操作!", str_cp);
                                return ret;
                            }*/

                            //挂失和删除代收表中Biao_Id
                            var ids_of_dlds_raw = from dqdr in ds_dldaishou.Tables[0].AsEnumerable()
                                                  select dqdr.Field<string>("Biao_Id");
                            var ids_of_dlds = ids_of_dlds_raw.Except(ids_of_ds_cp);

                            //完结代收表中Biao_Id
                            var ids_of_ods_raw = from oqdr in ds_overdaishou.Tables[0].AsEnumerable()
                                                 select oqdr.Field<string>("Biao_Id");
                            var ids_of_ods = ids_of_ods_raw.Except(ids_of_ds_cp);

                            //正常代收表中排除已挂失、删除和完结后的Biao_Id
                            var ids_of_ds_dis_di_o = ids_of_ds.Except(ids_of_dlds).Except(ids_of_ods);

                            //所有数据库中不能查出的Biao_Id
                            var ids_of_dball = ids_of_ds.Concat(ids_of_dlds).Concat(ids_of_ods).Distinct();
                            var ids_of_query = allQueryBiaoIds.Except(ids_of_ds_cp).Except(ids_of_dball);

                            //挂失和删除代收表中排除已完结后的Biao_Id
                            var ids_of_dlds_dis_o = ids_of_dlds.Except(ids_of_ods);

                            //正常代收表
                            var dataset_ds = from nqdr in ds_daishou.Tables[0].AsEnumerable()
                                             join id in ids_of_ds_dis_di_o
                                             on nqdr.Field<string>("Biao_Id") equals id
                                             select nqdr;

                            //正常代收表有权限
                            var dataset_ds_qxok = from nqdr in ds_daishou_qxok.Tables[0].AsEnumerable()
                                                  join id in ids_of_ds_dis_di_o
                                                  on nqdr.Field<string>("Biao_Id") equals id
                                                  select nqdr;

                            //挂失和删除代收表
                            var dataset_ds_dl = from dqdr in ds_dldaishou.Tables[0].AsEnumerable()
                                                join id in ids_of_dlds_dis_o
                                                on dqdr.Field<string>("Biao_Id") equals id
                                                select dqdr;

                            //完结代收表
                            var dataset_ds_o = from oqdr in ds_overdaishou.Tables[0].AsEnumerable()
                                               select oqdr;
                            //合并所有代收表
                            var ids_of_ds_allnet = from dqdr in dataset_ds
                                                   select dqdr.Field<string>("Biao_Id");
                            var ids_of_ds_qxnet = from dqdr in dataset_ds_qxok
                                                  select dqdr.Field<string>("Biao_Id");
                            var ids_of_ds_qxnotok = ids_of_ds_allnet.Except(ids_of_ds_qxnet);

                            //正常代收表中无权限的
                            var dataset_ds_qxnotok = from nqdr in ds_daishou.Tables[0].AsEnumerable()
                                                     join id in ids_of_ds_qxnotok
                                                     on nqdr.Field<string>("Biao_Id") equals id
                                                     select nqdr;

                            var dataset_all = dataset_ds_qxok.Concat(dataset_ds_dl).Concat(dataset_ds_o);

                            //按代收款状态排序后再按单号升序排序所有代收表
                            var dataset_all_orderded = from one in dataset_all
                                                       orderby one.Field<string>("Biao_Status"), one.Field<string>("Biao_Id") ascending
                                                       select one;

                            var dataset_all_orderded_qxnotok = from one in dataset_ds_qxnotok
                                                               orderby one.Field<string>("Biao_Status"), one.Field<string>("Biao_Id") ascending
                                                               select one;

                            var dataset_all_kehuanpiao = from one in dataset_ds_qxok
                                                         where one.Field<string>("Biao_Status") == KEHUANPIAO_STATUS
                                                         select one;

                            #endregion

                            #region 组装返回

                            //1.返回所有查询单号状态和详细信息
                            DataTable dt = dt = ds_daishou.Tables[0];

                            List<Dictionary<string, string>> one_ListImpl = new List<Dictionary<string, string>>();

                            logRecode.Info("5== ---------------------1");

                            //将不存在的运单标志为不存在状态后返回
                            foreach (var id in ids_of_query)
                            {
                                Dictionary<string, string> one_ydImpl = new Dictionary<string, string>();
                                one_ydImpl.Add("Biao_Id", id);
                                one_ydImpl.Add("Biao_Status", IDISNOTEXIST);
                                one_ListImpl.Add(one_ydImpl);

                                logRecode.Info(id + " : " + IDISNOTEXIST);
                            }
                            //将重票的运单标志为重票后返回
                            foreach (var id in ids_of_ds_cp)
                            {
                                Dictionary<string, string> one_ydImpl = new Dictionary<string, string>();
                                one_ydImpl.Add("Biao_Id", id);
                                one_ydImpl.Add("Biao_Status", IDISEXISTALD);
                                one_ListImpl.Add(one_ydImpl);

                                logRecode.Info(id + " : " + IDISEXISTALD);
                            }
                            //将排序后所有能查出的代收款返回,包括有权限和无权限的
                            foreach (DataRow dr in dataset_all_orderded_qxnotok)
                            {
                                Dictionary<string, string> one_ydImpl = new Dictionary<string, string>();
                                foreach (DataColumn dc in dt.Columns)
                                {
                                    if (dc.ColumnName == "Biao_Status")
                                    {
                                        one_ydImpl.Add(dc.ColumnName, dr[dc.ColumnName].ToString() + IDIS_QXNOTOK);
                                    }
                                    else
                                    {
                                        one_ydImpl.Add(dc.ColumnName, dr[dc.ColumnName].ToString());
                                    }
                                }
                                one_ListImpl.Add(one_ydImpl);

                                logRecode.Info(dr["Biao_Id"].ToString() + " : " + dr["Biao_Status"].ToString() + IDIS_QXNOTOK);
                            }
                            foreach (DataRow dr in dataset_all_orderded)
                            {
                                Dictionary<string, string> one_ydImpl = new Dictionary<string, string>();
                                foreach (DataColumn dc in dt.Columns)
                                {
                                    one_ydImpl.Add(dc.ColumnName, dr[dc.ColumnName].ToString());
                                }
                                one_ListImpl.Add(one_ydImpl);

                                logRecode.Info(dr["Biao_Id"].ToString() + " : " + dr["Biao_Status"].ToString());
                            }

                            logRecode.Info("5== ---------------------2");

                            ret.List_MapArgs = one_ListImpl;

                            //2.保存所有可换票单号状态、详细信息和换票配置信息，用作换票时判断状态是否已变
                            Dictionary<string, List<Dictionary<string, string>>> mapListMapImpl = new Dictionary<string, List<Dictionary<string, string>>>();
                            List<Dictionary<string, string>> listMapImpl = new List<Dictionary<string, string>>();
                            List<Dictionary<string, string>> idlistMapImpl = new List<Dictionary<string, string>>();
                            List<Dictionary<string, string>> cwsettinglistMapImpl = new List<Dictionary<string, string>>();
                            List<Dictionary<string, string>> outretlistMapImpl = new List<Dictionary<string, string>>();
                            Dictionary<string, string> outretImpl = new Dictionary<string, string>();
                            outretlistMapImpl.Add(outretImpl);
                            mapListMapImpl.Add(KEHUANPIAO_ALL_KEY, listMapImpl);
                            mapListMapImpl.Add(KEHUANPIAO_ID_KEY, idlistMapImpl);
                            mapListMapImpl.Add(INI_HUANPIAO_SETTING, cwsettinglistMapImpl);
                            mapListMapImpl.Add(INI_HUANPIAO_SETTING_OUTER, outretlistMapImpl);
                            foreach (DataRow dr in dataset_all_kehuanpiao)
                            {
                                //可换票详细清单
                                Dictionary<string, string> one_ydImpl = new Dictionary<string, string>();
                                foreach (DataColumn dc in dt.Columns)
                                {
                                    one_ydImpl.Add(dc.ColumnName, dr[dc.ColumnName].ToString());
                                }

                                logRecode.Info(dr["Biao_Id"].ToString() + " : " + dr["Biao_Status"].ToString());

                                listMapImpl.Add(one_ydImpl);
                                //可换票Id列表，用作在确认换票时提交服务器
                                Dictionary<string, string> idone_ydImpl = new Dictionary<string, string>();
                                idone_ydImpl.Add(dr["Biao_Id"].ToString(), "");
                                idlistMapImpl.Add(idone_ydImpl);
                            }
                            logRecode.Info("5== ---------------------3");
                            //换票设置信息
                            string PathStr = "D://CompanyConfig//" + dr_loginfo["Log_companyaccount"].ToString() + "//SettingDir//CaiWuSetting.ini";
                            csIniFiles CIni = new csIniFiles(PathStr);
                            string typeStr = CIni.ReadString(INI_HUANPIAO_SETTING, INI_HUANPIAO_SETTING_TYPE, "");
                            string dbzStr = CIni.ReadString(INI_HUANPIAO_SETTING, INI_HUANPIAO_SETTING_DBZ, "");
                            string dbmStr = CIni.ReadString(INI_HUANPIAO_SETTING, INI_HUANPIAO_SETTING_DBM, "");
                            string hbzStr = CIni.ReadString(INI_HUANPIAO_SETTING, INI_HUANPIAO_SETTING_HBZ, "");
                            string hbmStr = CIni.ReadString(INI_HUANPIAO_SETTING, INI_HUANPIAO_SETTING_HBM, "");
                            string pjStr = CIni.ReadString(INI_HUANPIAO_SETTING, INI_HUANPIAO_SETTING_PJ, "");
                            Dictionary<string, string> settingone_ydImpl = new Dictionary<string, string>();
                            settingone_ydImpl.Add(INI_HUANPIAO_SETTING_TYPE, typeStr);
                            settingone_ydImpl.Add(INI_HUANPIAO_SETTING_DBZ, dbzStr);
                            settingone_ydImpl.Add(INI_HUANPIAO_SETTING_DBM, dbmStr);
                            settingone_ydImpl.Add(INI_HUANPIAO_SETTING_HBZ, hbzStr);
                            settingone_ydImpl.Add(INI_HUANPIAO_SETTING_HBM, hbmStr);
                            settingone_ydImpl.Add(INI_HUANPIAO_SETTING_PJ, pjStr);
                            cwsettinglistMapImpl.Add(settingone_ydImpl);

                            //3.生成所有可换票单号手续费用等信息
                            if (typeStr == INI_HUANPIAO_SETTING_TYPE_DB)
                            {
                                Int64 pit = 0;
                                Int64 dj_sxf = 0;
                                Int64 zj_ys = 0;
                                Int64 zj_ss = 0;
                                Int64 zj_ps = 0;
                                Int64 zj_sxf = 0;
                                foreach (DataRow dr in dataset_all_kehuanpiao)
                                {
                                    zj_ys += Convert.ToInt64(dr[INI_HUANPIAO_DBCLOUMNAME_YS].ToString());
                                    zj_ss += Convert.ToInt64(dr[INI_HUANPIAO_DBCLOUMNAME_SS].ToString());
                                    pit = (Int64)(Convert.ToInt64(dr[INI_HUANPIAO_DBCLOUMNAME_SS].ToString()) / Convert.ToDouble(dbmStr));
                                    pit = (Convert.ToInt64(dr[INI_HUANPIAO_DBCLOUMNAME_SS].ToString()) > Convert.ToDouble(dbmStr) * pit) ? ++pit : pit;
                                    dj_sxf = (Int64)(Convert.ToDouble(dbzStr) * pit);
                                    zj_sxf += dj_sxf;
                                    zj_ps++;
                                }

                                ret.Map_Args.Add(INI_HUANPIAO_DBCLOUMNAME_YS, zj_ys.ToString());
                                ret.Map_Args.Add(INI_HUANPIAO_DBCLOUMNAME_SS, zj_ss.ToString());
                                ret.Map_Args.Add(INI_HUANPIAO_DBCLOUMNAME_SXF, zj_sxf.ToString());
                                ret.Map_Args.Add(INI_HUANPIAO_ZJ_KEHUANPIAO, zj_ps.ToString());

                                outretImpl.Add(INI_HUANPIAO_DBCLOUMNAME_YS, zj_ys.ToString());
                                outretImpl.Add(INI_HUANPIAO_DBCLOUMNAME_SS, zj_ss.ToString());
                                outretImpl.Add(INI_HUANPIAO_DBCLOUMNAME_SXF, zj_sxf.ToString());
                                outretImpl.Add(INI_HUANPIAO_ZJ_KEHUANPIAO, zj_ps.ToString());
                            }
                            else if (typeStr == INI_HUANPIAO_SETTING_TYPE_HB)
                            {
                                Int64 zj_ys = 0;
                                Int64 zj_ss = 0;
                                Int64 zj_ps = 0;
                                Int64 zj_sxf = 0;
                                foreach (DataRow dr in dataset_all_kehuanpiao)
                                {
                                    zj_ys += Convert.ToInt64(dr[INI_HUANPIAO_DBCLOUMNAME_YS].ToString());
                                    zj_ss += Convert.ToInt64(dr[INI_HUANPIAO_DBCLOUMNAME_SS].ToString());
                                    zj_ps++;
                                }
                                Int64 pit = (Int64)(zj_ss / Convert.ToDouble(hbmStr));
                                pit = (zj_ss > Convert.ToDouble(hbmStr) * pit) ? ++pit : pit;
                                zj_sxf = (Int64)(Convert.ToDouble(hbzStr) * pit);

                                ret.Map_Args.Add(INI_HUANPIAO_DBCLOUMNAME_YS, zj_ys.ToString());
                                ret.Map_Args.Add(INI_HUANPIAO_DBCLOUMNAME_SS, zj_ss.ToString());
                                ret.Map_Args.Add(INI_HUANPIAO_DBCLOUMNAME_SXF, zj_sxf.ToString());
                                ret.Map_Args.Add(INI_HUANPIAO_ZJ_KEHUANPIAO, zj_ps.ToString());

                                outretImpl.Add(INI_HUANPIAO_DBCLOUMNAME_YS, zj_ys.ToString());
                                outretImpl.Add(INI_HUANPIAO_DBCLOUMNAME_SS, zj_ss.ToString());
                                outretImpl.Add(INI_HUANPIAO_DBCLOUMNAME_SXF, zj_sxf.ToString());
                                outretImpl.Add(INI_HUANPIAO_ZJ_KEHUANPIAO, zj_ps.ToString());
                            }
                            else if (typeStr == INI_HUANPIAO_SETTING_TYPE_HZ)
                            {
                                Double pit = Convert.ToDouble(pjStr);
                                Int64 zj_ys = 0;
                                Int64 zj_ss = 0;
                                Int64 zj_ps = 0;
                                Double zj_sxf = 0;
                                foreach (DataRow dr in dataset_all_kehuanpiao)
                                {
                                    zj_ys += Convert.ToInt64(dr[INI_HUANPIAO_DBCLOUMNAME_YS].ToString());
                                    zj_ss += Convert.ToInt64(dr[INI_HUANPIAO_DBCLOUMNAME_SS].ToString());
                                    zj_sxf += pit;
                                    zj_ps++;
                                }

                                ret.Map_Args.Add(INI_HUANPIAO_DBCLOUMNAME_YS, zj_ys.ToString());
                                ret.Map_Args.Add(INI_HUANPIAO_DBCLOUMNAME_SS, zj_ss.ToString());
                                ret.Map_Args.Add(INI_HUANPIAO_DBCLOUMNAME_SXF, ((Int64)zj_sxf).ToString());
                                ret.Map_Args.Add(INI_HUANPIAO_ZJ_KEHUANPIAO, zj_ps.ToString());

                                outretImpl.Add(INI_HUANPIAO_DBCLOUMNAME_YS, zj_ys.ToString());
                                outretImpl.Add(INI_HUANPIAO_DBCLOUMNAME_SS, zj_ss.ToString());
                                outretImpl.Add(INI_HUANPIAO_DBCLOUMNAME_SXF, ((Int64)zj_sxf).ToString());
                                outretImpl.Add(INI_HUANPIAO_ZJ_KEHUANPIAO, zj_ps.ToString());
                            }
                            else
                            {
                                ret.Map_Args["ErrorMsg"] = "换票财务设置错误";
                                return ret;
                            }

                            ret.Maplist_MapArgs = mapListMapImpl;

                            #endregion

                            con.Close();
                        }

                        ts.Complete();
                    }
                }
                catch (System.Exception e)
                {
                    ret.Map_Args["ErrorMsg"] = e.Message;
                    return ret;
                }

                #endregion

                #region //组装返回值

                ret.Map_Args["ErrorMsg"] = "";
                ret.Byte_Flag = (sbyte)0;  //正常有效返回

                #endregion

            }
            catch (System.Exception e)
            {
                ret.Map_Args["ErrorMsg"] = e.Message;
                return ret;
            }

            return ret;
        }

        //手机修改用户密码
        public static ComThriftMsg Phone_ChangePswNew(string msg)
        {
            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            try
            {
                #region //反序列化

                byte[] bytrcv = Convert.FromBase64String(msg);
                ComThriftMsg comrcv = CommonTools.ByteTOComThriftAESD(bytrcv);

                if (!comrcv.__isset.struct_sqlinfo)
                {
                    ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                    return ret;
                }
                else
                {
                    if (!(comrcv.Struct_sqlinfo.__isset.string_sqlip && comrcv.Struct_sqlinfo.__isset.string_sqlname && comrcv.Struct_sqlinfo.__isset.string_sqlport
                        && comrcv.Struct_sqlinfo.__isset.string_sqlpwd && comrcv.Struct_sqlinfo.__isset.string_sqluser && comrcv.Struct_sqlinfo.__isset.string_useridkey))
                    {
                        ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                        return ret;
                    }
                }

                if (!comrcv.__isset.map_Args)
                {
                    ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                    return ret;
                }
                else
                {
                    if (!comrcv.Map_Args.Keys.Contains("NewPassword") || !comrcv.Map_Args.Keys.Contains("OldPassword"))
                    {
                        ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                        return ret;
                    }
                }
                #endregion

                #region //效验IDkey

                DataRow dr_loginfo = CheckNetIdkey(comrcv.Struct_sqlinfo);
                if (dr_loginfo == null)
                {
                    ret.Byte_Flag = (sbyte)-2;
                    ret.Map_Args["ErrorMsg"] = "IDKey无效";
                    return ret;
                }

                #endregion
                ILog logJieKou = LogManager.GetLogger("LoggerJieKou");
                logJieKou.Info("手机修改用户密码" + "-" + dr_loginfo["Log_companyname"].ToString() + "-" + dr_loginfo["Log_netname"].ToString());
                #region //生成数据量连接信息

                MySqlHelperEx mysqlhelperexImpl = new MySqlHelperEx();
                mysqlhelperexImpl.DB_CharacterSet = "utf8";

                mysqlhelperexImpl.DB_Server = comrcv.Struct_sqlinfo.String_sqlip;
                mysqlhelperexImpl.DB_Database = comrcv.Struct_sqlinfo.String_sqlname;
                mysqlhelperexImpl.DB_Port = comrcv.Struct_sqlinfo.String_sqlport;
                mysqlhelperexImpl.DB_UserID = comrcv.Struct_sqlinfo.String_sqluser;
                //mysqlhelperexImpl.DB_Password = comrcv.Struct_sqlinfo.String_sqlpwd;
                mysqlhelperexImpl.DB_Password = MySqlPwd;

                #endregion

                #region //从数据库获取信息

                string idkeystr = Guid.NewGuid().ToString();
                try
                {
                    using (TransactionScope ts = new TransactionScope())
                    {
                        using (MySqlConnection con = new MySqlConnection(mysqlhelperexImpl.GetConnectStr()))
                        {
                            con.Open();

                            //效验员工账号
                            string commandText = string.Format("SELECT * FROM {0} WHERE Fuser= ?companyAcc AND Account = ?employeeAcc;", dr_loginfo["Log_companyaccount"].ToString() + EMPLOYEEBIAONAME);
                            MySqlParameter[] msqlp = new MySqlParameter[2];
                            msqlp[0] = new MySqlParameter("?companyAcc", dr_loginfo["Log_companyaccount"].ToString());
                            msqlp[1] = new MySqlParameter("?employeeAcc", dr_loginfo["Log_ygaccount"].ToString());

                            DataRow sdr_employee = mysqlhelperexImpl.ExecuteDataRow(con, commandText, msqlp);
                            if (sdr_employee == null)
                            {
                                ret.Map_Args["ErrorMsg"] = "员工账号不存在";  //员工账号不存在
                                return ret;
                            }
                            else
                            {
                                if (sdr_employee["Password"].ToString() != comrcv.Map_Args["OldPassword"].ToString())
                                {
                                    ret.Map_Args["ErrorMsg"] = "旧密码错误";  //旧密码错误
                                    return ret;
                                }
                            }

                            //更新IDKey
                            commandText = string.Format("UPDATE {0} SET Log_idkey = ?idkey WHERE Log_companyaccount = ?companyAcc AND Log_ygaccount = ?employeeAcc;", "systemlogbiao");
                            msqlp = new MySqlParameter[3];
                            msqlp[0] = new MySqlParameter("?idkey", idkeystr);
                            msqlp[1] = new MySqlParameter("?companyAcc", dr_loginfo["Log_companyaccount"].ToString());
                            msqlp[2] = new MySqlParameter("?employeeAcc", dr_loginfo["Log_ygaccount"].ToString());

                            int exeret = mysqlhelperexImpl.ExecuteNonQuery(con, commandText, msqlp);
                            if (exeret < 1)
                            {
                                //更新失败
                                ret.Map_Args["ErrorMsg"] = "更新IDKey失败";  //更新IDKey失败
                                return ret;
                            }

                            //更新密码
                            commandText = string.Format("UPDATE {0} SET Password = ?pwd WHERE Fuser= ?companyAcc AND Account = ?employeeAcc;", dr_loginfo["Log_companyaccount"].ToString() + EMPLOYEEBIAONAME);
                            msqlp = new MySqlParameter[3];
                            msqlp[0] = new MySqlParameter("?pwd", comrcv.Map_Args["NewPassword"]);
                            msqlp[1] = new MySqlParameter("?companyAcc", dr_loginfo["Log_companyaccount"].ToString());
                            msqlp[2] = new MySqlParameter("?employeeAcc", dr_loginfo["Log_ygaccount"].ToString());

                            exeret = mysqlhelperexImpl.ExecuteNonQuery(con, commandText, msqlp);
                            if (exeret < 1)
                            {
                                //更新失败
                                ret.Map_Args["ErrorMsg"] = "更新密码失败";  //更新密码失败
                                return ret;
                            }

                            con.Close();
                        }

                        ts.Complete();
                    }
                }
                catch (System.Exception e)
                {
                    ret.Map_Args["ErrorMsg"] = e.Message;
                    return ret;
                }

                #endregion

                #region //组装返回值

                ret.Map_Args.Add("IdKey", idkeystr);
                ret.Map_Args["ErrorMsg"] = "";
                ret.Byte_Flag = (sbyte)0;  //正常有效返回

                #endregion

            }
            catch (System.Exception e)
            {
                ret.Map_Args["ErrorMsg"] = e.Message;
                return ret;
            }

            return ret;
        }

        //手机拉取财务配置信息
        public static ComThriftMsg Phone_DownloadCaiWuCfgNew(string msg)
        {
            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            try
            {
                #region //反序列化

                byte[] bytrcv = Convert.FromBase64String(msg);
                ComThriftMsg comrcv = CommonTools.ByteTOComThriftAESD(bytrcv);

                if (!comrcv.__isset.struct_sqlinfo)
                {
                    ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                    return ret;
                }
                else
                {
                    if (!(comrcv.Struct_sqlinfo.__isset.string_sqlip && comrcv.Struct_sqlinfo.__isset.string_sqlname && comrcv.Struct_sqlinfo.__isset.string_sqlport
                        && comrcv.Struct_sqlinfo.__isset.string_sqlpwd && comrcv.Struct_sqlinfo.__isset.string_sqluser && comrcv.Struct_sqlinfo.__isset.string_useridkey))
                    {
                        ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                        return ret;
                    }
                }

                if (!comrcv.__isset.maplist_MapArgs)
                {
                    ret.Map_Args["ErrorMsg"] = "";
                    ret.Byte_Flag = (sbyte)0;
                    return ret;
                }
                else
                {
                    if (comrcv.Maplist_MapArgs == null)
                    {
                        ret.Map_Args["ErrorMsg"] = "";
                        ret.Byte_Flag = (sbyte)0;
                        return ret;
                    }
                }
                #endregion

                #region //效验IDkey

                DataRow dr_loginfo = CheckNetIdkey(comrcv.Struct_sqlinfo);
                if (dr_loginfo == null)
                {
                    ret.Byte_Flag = (sbyte)-2;
                    ret.Map_Args["ErrorMsg"] = "IDKey无效";
                    return ret;
                }

                #endregion
                ILog logJieKou = LogManager.GetLogger("LoggerJieKou");
                logJieKou.Info("手机拉取财务配置信息" + "-" + dr_loginfo["Log_companyname"].ToString() + "-" + dr_loginfo["Log_netname"].ToString());
                #region //从配置文件获取信息

                string PathStr = "D://CompanyConfig//" + dr_loginfo["Log_companyaccount"].ToString() + "//SettingDir//CaiWuSetting.ini";
                csIniFiles CIni = new csIniFiles(PathStr);

                ret.Maplist_MapArgs = new Dictionary<string, List<Dictionary<string, string>>>();

                foreach (string maplistmaKey in comrcv.Maplist_MapArgs.Keys)
                {
                    List<Dictionary<string, string>> listmaImpl = new List<Dictionary<string, string>>();
                    ret.Maplist_MapArgs.Add(maplistmaKey, listmaImpl);
                    foreach (Dictionary<string, string> vmap in comrcv.Maplist_MapArgs[maplistmaKey])
                    {
                        Dictionary<string, string> mapImpl = new Dictionary<string, string>();
                        listmaImpl.Add(mapImpl);
                        foreach (string headKey in vmap.Keys)
                        {
                            string valueStr = CIni.ReadString(maplistmaKey, headKey, "");
                            mapImpl.Add(headKey, valueStr);
                        }
                    }
                }

                #endregion

                ret.Map_Args["ErrorMsg"] = "";
                ret.Byte_Flag = (sbyte)0;

            }
            catch (System.Exception e)
            {
                ret.Map_Args["ErrorMsg"] = e.Message;
                return ret;
            }

            return ret;
        }

        //手机拉取运单配置信息
        public static ComThriftMsg Phone_DownloadCfgNew(string msg)
        {
            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            try
            {
                #region //反序列化

                byte[] bytrcv = Convert.FromBase64String(msg);
                ComThriftMsg comrcv = CommonTools.ByteTOComThriftAESD(bytrcv);

                if (!comrcv.__isset.struct_sqlinfo)
                {
                    ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                    return ret;
                }
                else
                {
                    if (!(comrcv.Struct_sqlinfo.__isset.string_sqlip && comrcv.Struct_sqlinfo.__isset.string_sqlname && comrcv.Struct_sqlinfo.__isset.string_sqlport
                        && comrcv.Struct_sqlinfo.__isset.string_sqlpwd && comrcv.Struct_sqlinfo.__isset.string_sqluser && comrcv.Struct_sqlinfo.__isset.string_useridkey))
                    {
                        ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                        return ret;
                    }
                }

                if (!comrcv.__isset.maplist_MapArgs)
                {
                    ret.Map_Args["ErrorMsg"] = "";
                    ret.Byte_Flag = (sbyte)0;
                    return ret;
                }
                else
                {
                    if (comrcv.Maplist_MapArgs == null)
                    {
                        ret.Map_Args["ErrorMsg"] = "";
                        ret.Byte_Flag = (sbyte)0;
                        return ret;
                    }
                }
                #endregion

                #region //效验IDkey

                DataRow dr_loginfo = CheckNetIdkey(comrcv.Struct_sqlinfo);
                if (dr_loginfo == null)
                {
                    ret.Byte_Flag = (sbyte)-2;
                    ret.Map_Args["ErrorMsg"] = "IDKey无效";
                    return ret;
                }

                #endregion
                ILog logJieKou = LogManager.GetLogger("LoggerJieKou");
                logJieKou.Info("手机拉取运单配置信息" + "-" + dr_loginfo["Log_companyname"].ToString() + "-" + dr_loginfo["Log_netname"].ToString());
                #region //从配置文件获取信息

                string PathStr = "D://CompanyConfig//" + dr_loginfo["Log_companyaccount"].ToString() + "//SettingDir//GoodsSetting.ini";

                if (comrcv.Map_Args.ContainsKey("DuanXinIni") == true)
                {
                    PathStr = "D://CompanyConfig//" + dr_loginfo["Log_companyaccount"].ToString() + "//SettingDir//MsgSetting.ini";
                }

                csIniFiles CIni = new csIniFiles(PathStr);

                ret.Maplist_MapArgs = new Dictionary<string, List<Dictionary<string, string>>>();

                foreach (string maplistmaKey in comrcv.Maplist_MapArgs.Keys)
                {
                    List<Dictionary<string, string>> listmaImpl = new List<Dictionary<string, string>>();
                    ret.Maplist_MapArgs.Add(maplistmaKey, listmaImpl);
                    foreach (Dictionary<string, string> vmap in comrcv.Maplist_MapArgs[maplistmaKey])
                    {
                        Dictionary<string, string> mapImpl = new Dictionary<string, string>();
                        listmaImpl.Add(mapImpl);
                        foreach (string headKey in vmap.Keys)
                        {
                            string valueStr = CIni.ReadString(maplistmaKey, headKey, "");
                            mapImpl.Add(headKey, valueStr);
                        }
                    }
                }

                #endregion

                ret.Map_Args["ErrorMsg"] = "";
                ret.Byte_Flag = (sbyte)0;

            }
            catch (System.Exception e)
            {
                ret.Map_Args["ErrorMsg"] = e.Message;
                return ret;
            }

            return ret;
        }

        //手机下载离线运单号
        public static ComThriftMsg Phone_GetLiXianGoodsIdNew(string msg)
        {
            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            try
            {
                #region //反序列化

                byte[] bytrcv = Convert.FromBase64String(msg);
                ComThriftMsg comrcv = CommonTools.ByteTOComThriftAESD(bytrcv);

                if (!comrcv.__isset.struct_sqlinfo)
                {
                    ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                    return ret;
                }
                else
                {
                    if (!(comrcv.Struct_sqlinfo.__isset.string_sqlip && comrcv.Struct_sqlinfo.__isset.string_sqlname && comrcv.Struct_sqlinfo.__isset.string_sqlport
                        && comrcv.Struct_sqlinfo.__isset.string_sqlpwd && comrcv.Struct_sqlinfo.__isset.string_sqluser && comrcv.Struct_sqlinfo.__isset.string_useridkey))
                    {
                        ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                        return ret;
                    }
                }

                if (!comrcv.__isset.map_Args)
                {
                    ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                    return ret;
                }
                else
                {
                    if (!comrcv.Map_Args.Keys.Contains("Count"))
                    {
                        ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                        return ret;
                    }
                }
                #endregion

                #region //效验IDkey

                DataRow dr_loginfo = CheckNetIdkey(comrcv.Struct_sqlinfo);
                if (dr_loginfo == null)
                {
                    ret.Byte_Flag = (sbyte)-2;
                    ret.Map_Args["ErrorMsg"] = "IDKey无效";
                    return ret;
                }

                #endregion
                ILog logJieKou = LogManager.GetLogger("LoggerJieKou");
                logJieKou.Info("手机下载离线运单号" + "-" + dr_loginfo["Log_companyname"].ToString() + "-" + dr_loginfo["Log_netname"].ToString());
                #region //生成数据量连接信息

                MySqlHelperEx mysqlhelperexImpl = new MySqlHelperEx();
                mysqlhelperexImpl.DB_CharacterSet = "utf8";

                mysqlhelperexImpl.DB_Server = comrcv.Struct_sqlinfo.String_sqlip;
                mysqlhelperexImpl.DB_Database = comrcv.Struct_sqlinfo.String_sqlname;
                mysqlhelperexImpl.DB_Port = comrcv.Struct_sqlinfo.String_sqlport;
                mysqlhelperexImpl.DB_UserID = comrcv.Struct_sqlinfo.String_sqluser;
                //mysqlhelperexImpl.DB_Password = comrcv.Struct_sqlinfo.String_sqlpwd;
                mysqlhelperexImpl.DB_Password = MySqlPwd;

                #endregion

                #region //从数据库获取信息

                int thecount = 0;
                try
                {
                    using (TransactionScope ts = new TransactionScope())
                    {
                        using (MySqlConnection con = new MySqlConnection(mysqlhelperexImpl.GetConnectStr()))
                        {
                            con.Open();

                            string commandText = string.Format("SELECT GoodsIdnumber FROM {0} WHERE Account = ?companyAcc;"
                                , "user");
                            MySqlParameter[] msqlp = new MySqlParameter[1];
                            msqlp[0] = new MySqlParameter("?companyAcc", dr_loginfo["Log_companyaccount"].ToString());

                            object retobj = mysqlhelperexImpl.ExecuteScalar(con, commandText, msqlp);
                            if (retobj == null)
                            {
                                ret.Map_Args["ErrorMsg"] = "公司账号不存在";
                                return ret;
                            }

                            thecount = Convert.ToInt32(retobj);
                            int thenewcount = thecount + Convert.ToInt32(comrcv.Map_Args["Count"].ToString());

                            commandText = string.Format("UPDATE {0} SET GoodsIdnumber = ?newcount WHERE Account = ?companyAcc;"
                                , "user");
                            msqlp = new MySqlParameter[2];
                            msqlp[0] = new MySqlParameter("?newcount", thenewcount.ToString());
                            msqlp[1] = new MySqlParameter("?companyAcc", dr_loginfo["Log_companyaccount"].ToString());

                            int retint = mysqlhelperexImpl.ExecuteNonQuery(con, commandText, msqlp);
                            if (retint != 1)
                            {
                                ret.Map_Args["ErrorMsg"] = "更新数据库时错误";
                                return ret;
                            }
                            con.Close();
                        }

                        ts.Complete();
                    }
                }
                catch (System.Exception e)
                {
                    ret.Map_Args["ErrorMsg"] = e.Message;
                    return ret;
                }

                thecount++;
                ret.Map_Args["GoodsIdnumber"] = thecount.ToString();
                ret.Map_Args["ErrorMsg"] = "";
                ret.Byte_Flag = (sbyte)0;

                #endregion

            }
            catch (System.Exception e)
            {
                ret.Map_Args["ErrorMsg"] = e.Message;
                return ret;
            }

            return ret;
        }

        //手机获取客户
        public static ComThriftMsg Phone_GetCustomNew(string msg)
        {
            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            try
            {
                #region //反序列化

                byte[] bytrcv = Convert.FromBase64String(msg);
                ComThriftMsg comrcv = CommonTools.ByteTOComThriftAESD(bytrcv);

                if (!comrcv.__isset.struct_sqlinfo)
                {
                    ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                    return ret;
                }
                else
                {
                    if (!(comrcv.Struct_sqlinfo.__isset.string_sqlip && comrcv.Struct_sqlinfo.__isset.string_sqlname && comrcv.Struct_sqlinfo.__isset.string_sqlport
                        && comrcv.Struct_sqlinfo.__isset.string_sqlpwd && comrcv.Struct_sqlinfo.__isset.string_sqluser && comrcv.Struct_sqlinfo.__isset.string_useridkey))
                    {
                        ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                        return ret;
                    }
                }

                if (!comrcv.__isset.map_Args)
                {
                    ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                    return ret;
                }
                else
                {
                    if (!comrcv.Map_Args.Keys.Contains("Start") || !comrcv.Map_Args.Keys.Contains("Count"))
                    {
                        ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                        return ret;
                    }
                }
                #endregion

                #region //效验IDkey

                DataRow dr_loginfo = CheckNetIdkey(comrcv.Struct_sqlinfo);
                if (dr_loginfo == null)
                {
                    ret.Byte_Flag = (sbyte)-2;
                    ret.Map_Args["ErrorMsg"] = "IDKey无效";
                    return ret;
                }

                #endregion
                ILog logJieKou = LogManager.GetLogger("LoggerJieKou");
                logJieKou.Info("手机获取客户" + "-" + dr_loginfo["Log_companyname"].ToString() + "-" + dr_loginfo["Log_netname"].ToString());
                #region //生成数据量连接信息

                MySqlHelperEx mysqlhelperexImpl = new MySqlHelperEx();
                mysqlhelperexImpl.DB_CharacterSet = "utf8";

                mysqlhelperexImpl.DB_Server = comrcv.Struct_sqlinfo.String_sqlip;
                mysqlhelperexImpl.DB_Database = comrcv.Struct_sqlinfo.String_sqlname;
                mysqlhelperexImpl.DB_Port = comrcv.Struct_sqlinfo.String_sqlport;
                mysqlhelperexImpl.DB_UserID = comrcv.Struct_sqlinfo.String_sqluser;
                //mysqlhelperexImpl.DB_Password = comrcv.Struct_sqlinfo.String_sqlpwd;
                mysqlhelperexImpl.DB_Password = MySqlPwd;

                #endregion

                #region //从数据库获取信息

                string commandText = string.Format("SELECT Custom_Number,Custom_Name,Custom_Cellphone,Custom_Leixin,Custom_Changyundanjia,Custom_Mangoods,Custom_Place,"+
                    "Custom_Bank,Custom_Bankname,Custom_Bankaccount,Custom_Fanetaccounts,Custom_Shounetaccounts,Custom_Usid FROM {0} LIMIT {1} ,{2};"
                    , dr_loginfo["Log_companyaccount"].ToString() + CUSTOMBIAONAME, comrcv.Map_Args["Start"], comrcv.Map_Args["Count"]);

                DataSet ds_downuser = mysqlhelperexImpl.ExecuteDataset(commandText, (MySqlParameter[])null);
                if (ds_downuser == null)
                {
                    ret.Map_Args["ErrorMsg"] = "";
                    ret.Byte_Flag = (sbyte)0;
                }
                if (ds_downuser.Tables.Count == 0)
                {
                    ret.Map_Args["ErrorMsg"] = "";
                    ret.Byte_Flag = (sbyte)0;
                }
                if (ds_downuser.Tables[0].Rows.Count == 0)
                {
                    ret.Map_Args["ErrorMsg"] = "";
                    ret.Byte_Flag = (sbyte)0;
                }
                ret.List_MapArgs = new List<Dictionary<string, string>>();

                //获取该公司所有客户信息
                foreach (DataTable dt in ds_downuser.Tables)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        Dictionary<string, string> newNetImple = new Dictionary<string, string>();
                        foreach (DataColumn dl in dt.Columns)
                        {
                            newNetImple.Add(dl.ColumnName, dr[dl.ColumnName].ToString());
                        }
                        ret.List_MapArgs.Add(newNetImple);
                    }
                }

                ret.Map_Args["ErrorMsg"] = "";
                ret.Byte_Flag = (sbyte)0;

                #endregion
            }
            catch
            {
            }

            return ret;
        }

        //--------------------------------------------合并后的接口
        //手机所有相应信息
        public static ComThriftMsg Phone_GetAllInfoNew(string msg)
        {
            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            try
            {
                #region //反序列化

                byte[] bytrcv = Convert.FromBase64String(msg);
                ComThriftMsg comrcv = CommonTools.ByteTOComThriftAESD(bytrcv);

                if (!comrcv.__isset.struct_sqlinfo)
                {
                    ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                    return ret;
                }
                else
                {
                    if (!(comrcv.Struct_sqlinfo.__isset.string_sqlip && comrcv.Struct_sqlinfo.__isset.string_sqlname && comrcv.Struct_sqlinfo.__isset.string_sqlport
                        && comrcv.Struct_sqlinfo.__isset.string_sqlpwd && comrcv.Struct_sqlinfo.__isset.string_sqluser && comrcv.Struct_sqlinfo.__isset.string_useridkey))
                    {
                        ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                        return ret;
                    }
                }
                #endregion

                #region //效验IDkey

                DataRow dr_loginfo = CheckNetIdkey(comrcv.Struct_sqlinfo);
                if (dr_loginfo == null)
                {
                    ret.Byte_Flag = (sbyte)-2;
                    ret.Map_Args["ErrorMsg"] = "IDKey无效";
                    return ret;
                }

                #endregion
                ILog logJieKou = LogManager.GetLogger("LoggerJieKou");
                logJieKou.Info("手机所有相应信息" + "-" + dr_loginfo["Log_companyname"].ToString() + "-" + dr_loginfo["Log_netname"].ToString());
                #region //生成数据量连接信息

                MySqlHelperEx mysqlhelperexImpl = new MySqlHelperEx();
                mysqlhelperexImpl.DB_CharacterSet = "utf8";

                mysqlhelperexImpl.DB_Server = comrcv.Struct_sqlinfo.String_sqlip;
                mysqlhelperexImpl.DB_Database = comrcv.Struct_sqlinfo.String_sqlname;
                mysqlhelperexImpl.DB_Port = comrcv.Struct_sqlinfo.String_sqlport;
                mysqlhelperexImpl.DB_UserID = comrcv.Struct_sqlinfo.String_sqluser;
                //mysqlhelperexImpl.DB_Password = comrcv.Struct_sqlinfo.String_sqlpwd;
                mysqlhelperexImpl.DB_Password = MySqlPwd;

                #endregion

                #region //从数据库获取信息

                ret.Maplist_MapArgs = new Dictionary<string, List<Dictionary<string, string>>>();
                string commandText = "";
                MySqlParameter[] msqlp = null;

                #region //-------手机获取客户数量
                {
                    commandText = string.Format("SELECT COUNT(*) FROM {0};"
                        , dr_loginfo["Log_companyaccount"].ToString() + CUSTOMBIAONAME);

                    object ob_cus = mysqlhelperexImpl.ExecuteScalar(commandText);
                    if (ob_cus == null)
                    {
                        ret.Map_Args["ErrorMsg"] = "服务器数据库异常";
                        return ret;
                    }
                    ret.Map_Args.Add("ConsumerCount", Convert.ToString(ob_cus));
                }
                #endregion

                #region //-------手机获取所有其他网点信息
                {
                    commandText = string.Format("SELECT Name,Account,Place,Shortname,Telephone,Waizhuanlineaccount,Email,Qicq FROM {0} WHERE Account != ?netAcc AND Fuser = ?companyAcc AND Status='已开通';"
                        , dr_loginfo["Log_companyaccount"].ToString() + DOWNUSERBIAONAME);
                    msqlp = new MySqlParameter[2];
                    msqlp[0] = new MySqlParameter("?netAcc", dr_loginfo["Log_netaccount"].ToString());
                    msqlp[1] = new MySqlParameter("?companyAcc", dr_loginfo["Log_companyaccount"].ToString());

                    DataSet ds_downuser = mysqlhelperexImpl.ExecuteDataset(commandText, msqlp);
                    if (ds_downuser == null)
                    {
                        ret.Map_Args["ErrorMsg"] = "公司或网点账号不存在";
                        return ret;
                    }
                    if (ds_downuser.Tables.Count == 0)
                    {
                        ret.Map_Args["ErrorMsg"] = "公司或网点账号不存在";
                        return ret;
                    }
                    if (ds_downuser.Tables[0].Rows.Count == 0)
                    {
                        ret.Map_Args["ErrorMsg"] = "公司或网点账号不存在";
                        return ret;
                    }

                    List<Dictionary<string, string>> listmapImpl = new List<Dictionary<string, string>>();

                    //获取该公司所有其他网点信息
                    foreach (DataTable dt in ds_downuser.Tables)
                    {
                        foreach (DataRow dr in dt.Rows)
                        {
                            Dictionary<string, string> newNetImple = new Dictionary<string, string>();
                            foreach (DataColumn dl in dt.Columns)
                            {
                                newNetImple.Add(dl.ColumnName, dr[dl.ColumnName].ToString());
                            }
                            listmapImpl.Add(newNetImple);
                        }
                    }
                    ret.Maplist_MapArgs.Add("Phone_GetAllNetsNew", listmapImpl);
                    ds_downuser.Dispose();
                }
                #endregion

                #region //-------手机获取线路网点信息
                {
                    commandText = string.Format("SELECT * FROM {0} WHERE Account = ?netAcc AND Fuser = ?companyAcc;"
                    , dr_loginfo["Log_companyaccount"].ToString() + DOWNUSERBIAONAME);
                    msqlp = new MySqlParameter[2];
                    msqlp[0] = new MySqlParameter("?netAcc", dr_loginfo["Log_netaccount"].ToString());
                    msqlp[1] = new MySqlParameter("?companyAcc", dr_loginfo["Log_companyaccount"].ToString());

                    DataRow dr_downuser = mysqlhelperexImpl.ExecuteDataRow(commandText, msqlp);
                    if (dr_downuser == null)
                    {
                        ret.Map_Args["ErrorMsg"] = "公司或网点账号不存在";
                        return ret;
                    }

                    commandText = string.Format("SELECT Name,Account,Place,Shortname,Telephone,Waizhuanlineaccount,Qicq,Email FROM {0} WHERE Fuser = ?companyAcc AND Status='已开通';"
                        , dr_loginfo["Log_companyaccount"].ToString() + DOWNUSERBIAONAME);
                    msqlp = new MySqlParameter[1];
                    msqlp[0] = new MySqlParameter("?companyAcc", dr_loginfo["Log_companyaccount"].ToString());

                    DataSet ds_downuser = mysqlhelperexImpl.ExecuteDataset(commandText, msqlp);
                    if (ds_downuser == null)
                    {
                        ret.Map_Args["ErrorMsg"] = "公司或网点账号不存在";
                        return ret;
                    }
                    if (ds_downuser.Tables.Count == 0)
                    {
                        ret.Map_Args["ErrorMsg"] = "公司或网点账号不存在";
                        return ret;
                    }
                    if (ds_downuser.Tables[0].Rows.Count == 0)
                    {
                        ret.Map_Args["ErrorMsg"] = "公司或网点账号不存在";
                        return ret;
                    }

                    List<Dictionary<string, string>> listmapImpl = new List<Dictionary<string, string>>();

                    //获取该网点包含线路中的所有网点对应信息
                    foreach (DataTable dt in ds_downuser.Tables)
                    {
                        foreach (DataRow dr in dt.Rows)
                        {
                            if (dr_downuser["Lineaccount"].ToString() != "ALL")
                            {
                                if (!dr_downuser["Lineaccount"].ToString().Contains(dr["Account"].ToString()))
                                {
                                    continue;
                                }
                            }
                            if (dr["Account"].ToString() == dr_loginfo["Log_netaccount"].ToString())
                            {
                                continue;
                            }
                            Dictionary<string, string> newNetImple = new Dictionary<string, string>();
                            foreach (DataColumn dl in dt.Columns)
                            {
                                newNetImple.Add(dl.ColumnName, dr[dl.ColumnName].ToString());
                            }
                            listmapImpl.Add(newNetImple);
                        }
                    }
                    ret.Maplist_MapArgs.Add("Phone_GetMyOtherNetsNew", listmapImpl);
                    ds_downuser.Dispose();
                }
                #endregion

                #region //-------手机获取本人员工信息
                {
                    commandText = string.Format("SELECT Name,Male,Born,Phone,Bangongphone,Card,Intime,Authority,Companyauthority,Idkey FROM {0} WHERE Account = ?employeeAcc ;"
                    , dr_loginfo["Log_companyaccount"].ToString() + EMPLOYEEBIAONAME);
                    msqlp = new MySqlParameter[1];
                    msqlp[0] = new MySqlParameter("?employeeAcc", dr_loginfo["Log_ygaccount"].ToString());
  

                    DataRow dr_employee = mysqlhelperexImpl.ExecuteDataRow(commandText, msqlp);
                    if (dr_employee == null)
                    {
                        ret.Map_Args["ErrorMsg"] = "公司或网点账号不存在";
                        return ret;
                    }

                    Dictionary<string, string> newmapImpl = new Dictionary<string, string>();
                    List<Dictionary<string, string>> listmapImpl = new List<Dictionary<string, string>>();
                    foreach (DataColumn dl in dr_employee.Table.Columns)
                    {
                        newmapImpl.Add(dl.ColumnName, dr_employee[dl.ColumnName].ToString());
                    }
                    listmapImpl.Add(newmapImpl);
                    ret.Maplist_MapArgs.Add("Phone_GetMyEmployeeNew", listmapImpl);
                }
                #endregion

                #region //-------手机获取公司信息
                {
                    commandText = string.Format("SELECT * FROM {0} WHERE Account = ?companyAcc;", "user");
                    msqlp = new MySqlParameter[1];
                    msqlp[0] = new MySqlParameter("?companyAcc", dr_loginfo["Log_companyaccount"].ToString());

                    DataRow dr_user = mysqlhelperexImpl.ExecuteDataRow(commandText, msqlp);
                    if (dr_user == null)
                    {
                        ret.Map_Args["ErrorMsg"] = "公司或网点账号不存在";
                        return ret;
                    }

                    Dictionary<string, string> newmapImpl = new Dictionary<string, string>();
                    List<Dictionary<string, string>> listmapImpl = new List<Dictionary<string, string>>();
                    foreach (DataColumn dl in dr_user.Table.Columns)
                    {
                        newmapImpl.Add(dl.ColumnName, dr_user[dl.ColumnName].ToString());
                    }
                    listmapImpl.Add(newmapImpl);
                    ret.Maplist_MapArgs.Add("Phone_GetMyCompanyNew", listmapImpl);
                }
                #endregion

                #region //-------手机获取网点信息
                {
                    commandText = string.Format("SELECT Goodsnumber,Account,Status,Name,Shortname,Regtime,Place,Belong,Telephone,Cellphone,Manager,Mantelephone,Email,Qicq,Note FROM {0} WHERE Fuser = ?companyAcc AND Account = ?netAcc;"
                        , dr_loginfo["Log_companyaccount"].ToString() + DOWNUSERBIAONAME);
                    msqlp = new MySqlParameter[2];
                    msqlp[0] = new MySqlParameter("?companyAcc", dr_loginfo["Log_companyaccount"].ToString());
                    msqlp[1] = new MySqlParameter("?netAcc", dr_loginfo["Log_netaccount"].ToString());

                    DataRow dr_downuser = mysqlhelperexImpl.ExecuteDataRow(commandText, msqlp);
                    if (dr_downuser == null)
                    {
                        ret.Map_Args["ErrorMsg"] = "公司或网点账号不存在";
                        return ret;
                    }

                    Dictionary<string, string> newmapImpl = new Dictionary<string, string>();
                    List<Dictionary<string, string>> listmapImpl = new List<Dictionary<string, string>>();
                    foreach (DataColumn dl in dr_downuser.Table.Columns)
                    {
                        newmapImpl.Add(dl.ColumnName, dr_downuser[dl.ColumnName].ToString());
                    }
                    listmapImpl.Add(newmapImpl);
                    ret.Maplist_MapArgs.Add("Phone_GetNetMessageNew", listmapImpl);
                }
                #endregion

                ret.Map_Args["ErrorMsg"] = "";
                ret.Byte_Flag = (sbyte)0;

                #endregion

            }
            catch
            {
            }

            return ret;
        }
        //--------------------------------------------以下为可合并接口
        //手机获取客户数量
        public static ComThriftMsg Phone_GetAllCustomCountNew(string msg)
        {
            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            try
            {
                #region //反序列化

                byte[] bytrcv = Convert.FromBase64String(msg);
                ComThriftMsg comrcv = CommonTools.ByteTOComThriftAESD(bytrcv);

                if (!comrcv.__isset.struct_sqlinfo)
                {
                    ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                    return ret;
                }
                else
                {
                    if (!(comrcv.Struct_sqlinfo.__isset.string_sqlip && comrcv.Struct_sqlinfo.__isset.string_sqlname && comrcv.Struct_sqlinfo.__isset.string_sqlport
                        && comrcv.Struct_sqlinfo.__isset.string_sqlpwd && comrcv.Struct_sqlinfo.__isset.string_sqluser && comrcv.Struct_sqlinfo.__isset.string_useridkey))
                    {
                        ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                        return ret;
                    }
                }
                #endregion

                #region //效验IDkey

                DataRow dr_loginfo = CheckNetIdkey(comrcv.Struct_sqlinfo);
                if (dr_loginfo == null)
                {
                    ret.Byte_Flag = (sbyte)-2;
                    ret.Map_Args["ErrorMsg"] = "IDKey无效";
                    return ret;
                }

                #endregion
                ILog logJieKou = LogManager.GetLogger("LoggerJieKou");
                logJieKou.Info("手机获取客户数量" + "-" + dr_loginfo["Log_companyname"].ToString() + "-" + dr_loginfo["Log_netname"].ToString());
                #region //生成数据量连接信息

                MySqlHelperEx mysqlhelperexImpl = new MySqlHelperEx();
                mysqlhelperexImpl.DB_CharacterSet = "utf8";

                mysqlhelperexImpl.DB_Server = comrcv.Struct_sqlinfo.String_sqlip;
                mysqlhelperexImpl.DB_Database = comrcv.Struct_sqlinfo.String_sqlname;
                mysqlhelperexImpl.DB_Port = comrcv.Struct_sqlinfo.String_sqlport;
                mysqlhelperexImpl.DB_UserID = comrcv.Struct_sqlinfo.String_sqluser;
                //mysqlhelperexImpl.DB_Password = comrcv.Struct_sqlinfo.String_sqlpwd;
                mysqlhelperexImpl.DB_Password = MySqlPwd;

                #endregion

                #region //从数据库获取信息

                string commandText = string.Format("SELECT COUNT(*) FROM {0};"
                    , dr_loginfo["Log_companyaccount"].ToString() + CUSTOMBIAONAME);

                object ob_cus = mysqlhelperexImpl.ExecuteScalar(commandText);
                if (ob_cus == null)
                {
                    ret.Map_Args["ErrorMsg"] = "服务器数据库异常";
                    return ret;
                }

                //ret.Map_Args.Add("ConsumerCount", (string)ob_cus);
                ret.Map_Args.Add("ConsumerCount", Convert.ToString(ob_cus));
                ret.Map_Args["ErrorMsg"] = "";
                ret.Byte_Flag = (sbyte)0;

                #endregion

            }
            catch
            {
            }

            return ret;
        }

        //手机获取所有其他网点信息
        public static ComThriftMsg Phone_GetAllNetsNew(string msg)
        {
            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            try
            {
                #region //反序列化

                byte[] bytrcv = Convert.FromBase64String(msg);
                ComThriftMsg comrcv = CommonTools.ByteTOComThriftAESD(bytrcv);

                if (!comrcv.__isset.struct_sqlinfo)
                {
                    ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                    return ret;
                }
                else
                {
                    if (!(comrcv.Struct_sqlinfo.__isset.string_sqlip && comrcv.Struct_sqlinfo.__isset.string_sqlname && comrcv.Struct_sqlinfo.__isset.string_sqlport
                        && comrcv.Struct_sqlinfo.__isset.string_sqlpwd && comrcv.Struct_sqlinfo.__isset.string_sqluser && comrcv.Struct_sqlinfo.__isset.string_useridkey))
                    {
                        ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                        return ret;
                    }
                }
                #endregion

                #region //效验IDkey

                DataRow dr_loginfo = CheckNetIdkey(comrcv.Struct_sqlinfo);
                if (dr_loginfo == null)
                {
                    ret.Byte_Flag = (sbyte)-2;
                    ret.Map_Args["ErrorMsg"] = "IDKey无效";
                    return ret;
                }

                #endregion
                ILog logJieKou = LogManager.GetLogger("LoggerJieKou");
                logJieKou.Info("手机获取所有其他网点信息" + "-" + dr_loginfo["Log_companyname"].ToString() + "-" + dr_loginfo["Log_netname"].ToString());
                #region //生成数据量连接信息

                MySqlHelperEx mysqlhelperexImpl = new MySqlHelperEx();
                mysqlhelperexImpl.DB_CharacterSet = "utf8";

                mysqlhelperexImpl.DB_Server = comrcv.Struct_sqlinfo.String_sqlip;
                mysqlhelperexImpl.DB_Database = comrcv.Struct_sqlinfo.String_sqlname;
                mysqlhelperexImpl.DB_Port = comrcv.Struct_sqlinfo.String_sqlport;
                mysqlhelperexImpl.DB_UserID = comrcv.Struct_sqlinfo.String_sqluser;
                //mysqlhelperexImpl.DB_Password = comrcv.Struct_sqlinfo.String_sqlpwd;
                mysqlhelperexImpl.DB_Password = MySqlPwd;

                #endregion

                #region //从数据库获取信息

                string commandText = string.Format("SELECT Name,Account,Place,Shortname,Telephone,Waizhuanlineaccount,Qicq FROM {0} WHERE Account != ?netAcc AND Fuser = ?companyAcc;"
                    , dr_loginfo["Log_companyaccount"].ToString() + DOWNUSERBIAONAME);
                MySqlParameter[] msqlp = new MySqlParameter[2];
                msqlp[0] = new MySqlParameter("?netAcc", dr_loginfo["Log_netaccount"].ToString());
                msqlp[1] = new MySqlParameter("?companyAcc", dr_loginfo["Log_companyaccount"].ToString());

                DataSet ds_downuser = mysqlhelperexImpl.ExecuteDataset(commandText, msqlp);
                if (ds_downuser == null)
                {
                    ret.Map_Args["ErrorMsg"] = "公司或网点账号不存在";
                    return ret;
                }
                if (ds_downuser.Tables.Count == 0)
                {
                    ret.Map_Args["ErrorMsg"] = "公司或网点账号不存在";
                    return ret;
                }
                if (ds_downuser.Tables[0].Rows.Count == 0)
                {
                    ret.Map_Args["ErrorMsg"] = "公司或网点账号不存在";
                    return ret;
                }

                ret.List_MapArgs = new List<Dictionary<string, string>>();

                //获取该公司所有其他网点信息
                foreach (DataTable dt in ds_downuser.Tables)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        Dictionary<string, string> newNetImple = new Dictionary<string, string>();
                        foreach (DataColumn dl in dt.Columns)
                        {
                            newNetImple.Add(dl.ColumnName, dr[dl.ColumnName].ToString());
                        }
                        ret.List_MapArgs.Add(newNetImple);
                    }
                }

                ret.Map_Args["ErrorMsg"] = "";
                ret.Byte_Flag = (sbyte)0;

                #endregion

            }
            catch
            {
            }

            return ret;
        }

        //手机获取线路网点信息
        public static ComThriftMsg Phone_GetMyOtherNetsNew(string msg)
        {
            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            try
            {
                #region //反序列化

                byte[] bytrcv = Convert.FromBase64String(msg);
                ComThriftMsg comrcv = CommonTools.ByteTOComThriftAESD(bytrcv);

                if (!comrcv.__isset.struct_sqlinfo)
                {
                    ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                    return ret;
                }
                else
                {
                    if (!(comrcv.Struct_sqlinfo.__isset.string_sqlip && comrcv.Struct_sqlinfo.__isset.string_sqlname && comrcv.Struct_sqlinfo.__isset.string_sqlport
                        && comrcv.Struct_sqlinfo.__isset.string_sqlpwd && comrcv.Struct_sqlinfo.__isset.string_sqluser && comrcv.Struct_sqlinfo.__isset.string_useridkey))
                    {
                        ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                        return ret;
                    }
                }
                #endregion

                #region //效验IDkey

                DataRow dr_loginfo = CheckNetIdkey(comrcv.Struct_sqlinfo);
                if (dr_loginfo == null)
                {
                    ret.Byte_Flag = (sbyte)-2;
                    ret.Map_Args["ErrorMsg"] = "IDKey无效";
                    return ret;
                }

                #endregion
                ILog logJieKou = LogManager.GetLogger("LoggerJieKou");
                logJieKou.Info("手机获取线路网点信息" + "-" + dr_loginfo["Log_companyname"].ToString() + "-" + dr_loginfo["Log_netname"].ToString());
                #region //生成数据量连接信息

                MySqlHelperEx mysqlhelperexImpl = new MySqlHelperEx();
                mysqlhelperexImpl.DB_CharacterSet = "utf8";

                mysqlhelperexImpl.DB_Server = comrcv.Struct_sqlinfo.String_sqlip;
                mysqlhelperexImpl.DB_Database = comrcv.Struct_sqlinfo.String_sqlname;
                mysqlhelperexImpl.DB_Port = comrcv.Struct_sqlinfo.String_sqlport;
                mysqlhelperexImpl.DB_UserID = comrcv.Struct_sqlinfo.String_sqluser;
                //mysqlhelperexImpl.DB_Password = comrcv.Struct_sqlinfo.String_sqlpwd;
                mysqlhelperexImpl.DB_Password = MySqlPwd;

                #endregion

                #region //从数据库获取信息

                string commandText = string.Format("SELECT * FROM {0} WHERE Account = ?netAcc AND Fuser = ?companyAcc;"
                    , dr_loginfo["Log_companyaccount"].ToString() + DOWNUSERBIAONAME);
                MySqlParameter[] msqlp = new MySqlParameter[2];
                msqlp[0] = new MySqlParameter("?netAcc", dr_loginfo["Log_netaccount"].ToString());
                msqlp[1] = new MySqlParameter("?companyAcc", dr_loginfo["Log_companyaccount"].ToString());

                DataRow dr_downuser = mysqlhelperexImpl.ExecuteDataRow(commandText, msqlp);
                if (dr_downuser == null)
                {
                    ret.Map_Args["ErrorMsg"] = "公司或网点账号不存在";
                    return ret;
                }

                commandText = string.Format("SELECT Name,Account,Place,Shortname,Telephone,Waizhuanlineaccount,Qicq FROM {0} WHERE Fuser = ?companyAcc;"
                    , dr_loginfo["Log_companyaccount"].ToString() + DOWNUSERBIAONAME);
                msqlp = new MySqlParameter[1];
                msqlp[0] = new MySqlParameter("?companyAcc", dr_loginfo["Log_companyaccount"].ToString());

                DataSet ds_downuser = mysqlhelperexImpl.ExecuteDataset(commandText, msqlp);
                if (ds_downuser == null)
                {
                    ret.Map_Args["ErrorMsg"] = "公司或网点账号不存在";
                    return ret;
                }
                if (ds_downuser.Tables.Count == 0)
                {
                    ret.Map_Args["ErrorMsg"] = "公司或网点账号不存在";
                    return ret;
                }
                if (ds_downuser.Tables[0].Rows.Count == 0)
                {
                    ret.Map_Args["ErrorMsg"] = "公司或网点账号不存在";
                    return ret;
                }

                ret.List_MapArgs = new List<Dictionary<string, string>>();

                //获取该网点包含线路中的所有网点对应信息
                foreach (DataTable dt in ds_downuser.Tables)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        if (dr_downuser["Lineaccount"].ToString() != "ALL")
                        {

                            string Lineaccount = dr_downuser["Lineaccount"].ToString();
                            string[] AllSystemItemarr = Lineaccount.Split(';');
                            bool iscontinue = false;
                            for (int i = 0; i < AllSystemItemarr.Length - 1; i++)
                            {
                                if (AllSystemItemarr[i] == dr["Account"].ToString())
                                {
                                    iscontinue = true;
                                    break;
                                }
                                
                            }
                            if (iscontinue == false)
                            {
                                continue;
                            }
                        }
                        if (dr["Account"].ToString() == dr_loginfo["Log_netaccount"].ToString())
                        {
                            continue;
                        }
                        Dictionary<string, string> newNetImple = new Dictionary<string, string>();
                        foreach (DataColumn dl in dt.Columns)
                        {
                            newNetImple.Add(dl.ColumnName, dr[dl.ColumnName].ToString());
                        }
                        ret.List_MapArgs.Add(newNetImple);
                    }
                }

                ret.Map_Args["ErrorMsg"] = "";
                ret.Byte_Flag = (sbyte)0;

                #endregion

            }
            catch
            {
            }

            return ret;
        }

        //手机获取本人员工信息
        public static ComThriftMsg Phone_GetMyEmployeeNew(string msg)
        {
            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            try
            {
                #region //反序列化

                byte[] bytrcv = Convert.FromBase64String(msg);
                ComThriftMsg comrcv = CommonTools.ByteTOComThriftAESD(bytrcv);

                if (!comrcv.__isset.struct_sqlinfo)
                {
                    ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                    return ret;
                }
                else
                {
                    if (!(comrcv.Struct_sqlinfo.__isset.string_sqlip && comrcv.Struct_sqlinfo.__isset.string_sqlname && comrcv.Struct_sqlinfo.__isset.string_sqlport
                        && comrcv.Struct_sqlinfo.__isset.string_sqlpwd && comrcv.Struct_sqlinfo.__isset.string_sqluser && comrcv.Struct_sqlinfo.__isset.string_useridkey))
                    {
                        ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                        return ret;
                    }
                }
                #endregion

                #region //效验IDkey

                DataRow dr_loginfo = CheckNetIdkey(comrcv.Struct_sqlinfo);
                if (dr_loginfo == null)
                {
                    ret.Byte_Flag = (sbyte)-2;
                    ret.Map_Args["ErrorMsg"] = "IDKey无效";
                    return ret;
                }

                #endregion
                ILog logJieKou = LogManager.GetLogger("LoggerJieKou");
                logJieKou.Info("手机获取本人员工信息" + "-" + dr_loginfo["Log_companyname"].ToString() + "-" + dr_loginfo["Log_netname"].ToString());
                #region //生成数据量连接信息

                MySqlHelperEx mysqlhelperexImpl = new MySqlHelperEx();
                mysqlhelperexImpl.DB_CharacterSet = "utf8";

                mysqlhelperexImpl.DB_Server = comrcv.Struct_sqlinfo.String_sqlip;
                mysqlhelperexImpl.DB_Database = comrcv.Struct_sqlinfo.String_sqlname;
                mysqlhelperexImpl.DB_Port = comrcv.Struct_sqlinfo.String_sqlport;
                mysqlhelperexImpl.DB_UserID = comrcv.Struct_sqlinfo.String_sqluser;
                //mysqlhelperexImpl.DB_Password = comrcv.Struct_sqlinfo.String_sqlpwd;
                mysqlhelperexImpl.DB_Password = MySqlPwd;

                #endregion

                #region //从数据库获取信息

                string commandText = string.Format("SELECT Name,Male,Born,Phone,Card,Intime,Authority FROM {0} WHERE Account = ?employeeAcc AND Fuser = ?companyAcc;"
                    , dr_loginfo["Log_companyaccount"].ToString() + EMPLOYEEBIAONAME);
                MySqlParameter[] msqlp = new MySqlParameter[2];
                msqlp[0] = new MySqlParameter("?employeeAcc", dr_loginfo["Log_ygaccount"].ToString());
                msqlp[1] = new MySqlParameter("?companyAcc", dr_loginfo["Log_companyaccount"].ToString());

                DataRow dr_employee = mysqlhelperexImpl.ExecuteDataRow(commandText, msqlp);
                if (dr_employee == null)
                {
                    ret.Map_Args["ErrorMsg"] = "公司或网点账号不存在";
                    return ret;
                }

                foreach (DataColumn dl in dr_employee.Table.Columns)
                {
                    ret.Map_Args.Add(dl.ColumnName, dr_employee[dl.ColumnName].ToString());
                }

                ret.Map_Args["ErrorMsg"] = dr_employee["Authority"].ToString();
                ret.Byte_Flag = (sbyte)0;

                #endregion

            }
            catch
            {
            }

            return ret;
        }

        //手机获取公司信息
        public static ComThriftMsg Phone_GetMyCompanyNew(string msg)
        {
            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            try
            {
                #region //反序列化

                byte[] bytrcv = Convert.FromBase64String(msg);
                ComThriftMsg comrcv = CommonTools.ByteTOComThriftAESD(bytrcv);

                if (!comrcv.__isset.struct_sqlinfo)
                {
                    ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                    return ret;
                }
                else
                {
                    if (!(comrcv.Struct_sqlinfo.__isset.string_sqlip && comrcv.Struct_sqlinfo.__isset.string_sqlname && comrcv.Struct_sqlinfo.__isset.string_sqlport
                        && comrcv.Struct_sqlinfo.__isset.string_sqlpwd && comrcv.Struct_sqlinfo.__isset.string_sqluser && comrcv.Struct_sqlinfo.__isset.string_useridkey))
                    {
                        ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                        return ret;
                    }
                }
                #endregion

                #region //效验IDkey

                DataRow dr_loginfo = CheckNetIdkey(comrcv.Struct_sqlinfo);
                if (dr_loginfo == null)
                {
                    ret.Byte_Flag = (sbyte)-2;
                    ret.Map_Args["ErrorMsg"] = "IDKey无效";
                    return ret;
                }

                #endregion
                ILog logJieKou = LogManager.GetLogger("LoggerJieKou");
                logJieKou.Info("手机获取公司信息" + "-" + dr_loginfo["Log_companyname"].ToString() + "-" + dr_loginfo["Log_netname"].ToString());
                #region //生成数据量连接信息

                MySqlHelperEx mysqlhelperexImpl = new MySqlHelperEx();
                mysqlhelperexImpl.DB_CharacterSet = "utf8";

                mysqlhelperexImpl.DB_Server = comrcv.Struct_sqlinfo.String_sqlip;
                mysqlhelperexImpl.DB_Database = comrcv.Struct_sqlinfo.String_sqlname;
                mysqlhelperexImpl.DB_Port = comrcv.Struct_sqlinfo.String_sqlport;
                mysqlhelperexImpl.DB_UserID = comrcv.Struct_sqlinfo.String_sqluser;
                //mysqlhelperexImpl.DB_Password = comrcv.Struct_sqlinfo.String_sqlpwd;
                mysqlhelperexImpl.DB_Password = MySqlPwd;

                #endregion

                #region //从数据库获取信息

                string commandText = string.Format("SELECT * FROM {0} WHERE Account = ?companyAcc;", "user");
                MySqlParameter[] msqlp = new MySqlParameter[1];
                msqlp[0] = new MySqlParameter("?companyAcc", dr_loginfo["Log_companyaccount"].ToString());

                DataRow dr_user = mysqlhelperexImpl.ExecuteDataRow(commandText, msqlp);
                if (dr_user == null)
                {
                    ret.Map_Args["ErrorMsg"] = "公司或网点账号不存在";
                    return ret;
                }

                foreach (DataColumn dl in dr_user.Table.Columns)
                {
                    ret.Map_Args.Add(dl.ColumnName, dr_user[dl.ColumnName].ToString());
                }

                ret.Map_Args["ErrorMsg"] = "";
                ret.Byte_Flag = (sbyte)0;

                #endregion

            }
            catch
            {
            }

            return ret;
        }

        //手机获取网点信息
        public static ComThriftMsg Phone_GetNetMessageNew(string msg)
        {
            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            try
            {
                #region //反序列化

                byte[] bytrcv = Convert.FromBase64String(msg);
                ComThriftMsg comrcv = CommonTools.ByteTOComThriftAESD(bytrcv);

                if (!comrcv.__isset.struct_sqlinfo)
                {
                    ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                    return ret;
                }
                else
                {
                    if (!(comrcv.Struct_sqlinfo.__isset.string_sqlip && comrcv.Struct_sqlinfo.__isset.string_sqlname && comrcv.Struct_sqlinfo.__isset.string_sqlport
                        && comrcv.Struct_sqlinfo.__isset.string_sqlpwd && comrcv.Struct_sqlinfo.__isset.string_sqluser && comrcv.Struct_sqlinfo.__isset.string_useridkey))
                    {
                        ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                        return ret;
                    }
                }
                #endregion

                #region //效验IDkey

                DataRow dr_loginfo = CheckNetIdkey(comrcv.Struct_sqlinfo);
                if (dr_loginfo == null)
                {
                    ret.Byte_Flag = (sbyte)-2;
                    ret.Map_Args["ErrorMsg"] = "IDKey无效";
                    return ret;
                }

                #endregion
                ILog logJieKou = LogManager.GetLogger("LoggerJieKou");
                logJieKou.Info("手机获取网点信息" + "-" + dr_loginfo["Log_companyname"].ToString() + "-" + dr_loginfo["Log_netname"].ToString());
                #region //生成数据量连接信息

                MySqlHelperEx mysqlhelperexImpl = new MySqlHelperEx();
                mysqlhelperexImpl.DB_CharacterSet = "utf8";

                mysqlhelperexImpl.DB_Server = comrcv.Struct_sqlinfo.String_sqlip;
                mysqlhelperexImpl.DB_Database = comrcv.Struct_sqlinfo.String_sqlname;
                mysqlhelperexImpl.DB_Port = comrcv.Struct_sqlinfo.String_sqlport;
                mysqlhelperexImpl.DB_UserID = comrcv.Struct_sqlinfo.String_sqluser;
                //mysqlhelperexImpl.DB_Password = comrcv.Struct_sqlinfo.String_sqlpwd;
                mysqlhelperexImpl.DB_Password = MySqlPwd;

                #endregion

                #region //从数据库获取信息

                string commandText = string.Format("SELECT Goodsnumber,Account,Status,Name,Shortname,Regtime,Place,Belong,Telephone,Cellphone,Manager,Mantelephone,Email,Qicq,Note FROM {0} WHERE Fuser = ?companyAcc AND Account = ?netAcc;"
                    , dr_loginfo["Log_companyaccount"].ToString() + DOWNUSERBIAONAME);
                MySqlParameter[] msqlp = new MySqlParameter[2];
                msqlp[0] = new MySqlParameter("?companyAcc", dr_loginfo["Log_companyaccount"].ToString());
                msqlp[1] = new MySqlParameter("?netAcc", dr_loginfo["Log_netaccount"].ToString());

                DataRow dr_downuser = mysqlhelperexImpl.ExecuteDataRow(commandText, msqlp);
                if (dr_downuser == null)
                {
                    ret.Map_Args["ErrorMsg"] = "公司或网点账号不存在";
                    return ret;
                }

                foreach (DataColumn dl in dr_downuser.Table.Columns)
                {
                    ret.Map_Args.Add(dl.ColumnName, dr_downuser[dl.ColumnName].ToString());
                }

                ret.Map_Args["ErrorMsg"] = "";
                ret.Byte_Flag = (sbyte)0;

                #endregion

            }
            catch
            {
            }

            return ret;
        }
        //--------------------------------------------

        //手机获取服务器时间
        public static ComThriftMsg Phone_GetSystemUpdateNew(string msg)
        {
            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            try
            {
                #region //反序列化

                byte[] bytrcv = Convert.FromBase64String(msg);
                ComThriftMsg comrcv = CommonTools.ByteTOComThriftAESD(bytrcv);

                if (!comrcv.__isset.struct_sqlinfo)
                {
                    ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                    return ret;
                }
                else
                {
                    if (!(comrcv.Struct_sqlinfo.__isset.string_sqlip && comrcv.Struct_sqlinfo.__isset.string_sqlname && comrcv.Struct_sqlinfo.__isset.string_sqlport
                        && comrcv.Struct_sqlinfo.__isset.string_sqlpwd && comrcv.Struct_sqlinfo.__isset.string_sqluser && comrcv.Struct_sqlinfo.__isset.string_useridkey))
                    {
                        ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                        return ret;
                    }
                }
                #endregion

                #region //效验IDkey

                DataRow dr_loginfo = CheckNetIdkey(comrcv.Struct_sqlinfo);
                if (dr_loginfo == null)
                {
                    ret.Byte_Flag = (sbyte)-2;
                    ret.Map_Args["ErrorMsg"] = "IDKey无效";
                    return ret;
                }

                #endregion
                ILog logJieKou = LogManager.GetLogger("LoggerJieKou");
                logJieKou.Info("手机获取服务器时间" + "-" + dr_loginfo["Log_companyname"].ToString() + "-" + dr_loginfo["Log_netname"].ToString());
                #region //生成数据量连接信息

                MySqlHelperEx mysqlhelperexImpl = new MySqlHelperEx();
                mysqlhelperexImpl.DB_CharacterSet = "utf8";

                mysqlhelperexImpl.DB_Server = comrcv.Struct_sqlinfo.String_sqlip;
                mysqlhelperexImpl.DB_Database = comrcv.Struct_sqlinfo.String_sqlname;
                mysqlhelperexImpl.DB_Port = comrcv.Struct_sqlinfo.String_sqlport;
                mysqlhelperexImpl.DB_UserID = comrcv.Struct_sqlinfo.String_sqluser;
                //mysqlhelperexImpl.DB_Password = comrcv.Struct_sqlinfo.String_sqlpwd;
                mysqlhelperexImpl.DB_Password = MySqlPwd;

                #endregion

                #region //从数据库获取信息

                string commandText = string.Format("SELECT Buytime,Phonelogtime FROM {0} WHERE Account = ?companyAcc;", "user");
                MySqlParameter[] msqlp = new MySqlParameter[1];
                msqlp[0] = new MySqlParameter("?companyAcc", dr_loginfo["Log_companyaccount"].ToString());

                DataRow dr_user = mysqlhelperexImpl.ExecuteDataRow(commandText, msqlp);
                if (dr_user == null)
                {
                    ret.Map_Args["ErrorMsg"] = "公司账号不存在";
                    return ret;
                }
                ret.Map_Args.Add("Systemtime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                ret.Map_Args.Add("Buytime", dr_user["Buytime"].ToString());
                ret.Map_Args.Add("Phonelogtime", dr_user["Phonelogtime"].ToString());

                ret.Map_Args["ErrorMsg"] = "";
                ret.Byte_Flag = (sbyte)0;

                #endregion

            }
            catch
            {
            }

            return ret;
        }

        //手机获取软件更新
        public static ComThriftMsg Phone_VersionNew(string msg)
        {
            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            try
            {
                #region //反序列化

                byte[] bytrcv = Convert.FromBase64String(msg);
                ComThriftMsg comrcv = CommonTools.ByteTOComThriftAESD(bytrcv);

                if (!comrcv.__isset.struct_sqlinfo)
                {
                    ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                    return ret;
                }
                else
                {
                    if (!(comrcv.Struct_sqlinfo.__isset.string_sqlip && comrcv.Struct_sqlinfo.__isset.string_sqlname && comrcv.Struct_sqlinfo.__isset.string_sqlport
                        && comrcv.Struct_sqlinfo.__isset.string_sqlpwd && comrcv.Struct_sqlinfo.__isset.string_sqluser && comrcv.Struct_sqlinfo.__isset.string_useridkey))
                    {
                        ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                        return ret;
                    }
                }
                #endregion

                #region //效验IDkey

                DataRow dr_loginfo = CheckNetIdkey(comrcv.Struct_sqlinfo);
                if (dr_loginfo == null)
                {
                    ret.Byte_Flag = (sbyte)-2;
                    ret.Map_Args["ErrorMsg"] = "IDKey无效";
                    return ret;
                }

                #endregion
                ILog logJieKou = LogManager.GetLogger("LoggerJieKou");
                logJieKou.Info("手机获取软件更新" + "-" + dr_loginfo["Log_companyname"].ToString() + "-" + dr_loginfo["Log_netname"].ToString());
                #region //生成数据量连接信息
                /*
                MySqlHelperEx mysqlhelperexImpl = new MySqlHelperEx();
                mysqlhelperexImpl.DB_CharacterSet = "utf8";

                mysqlhelperexImpl.DB_Server = comrcv.Struct_sqlinfo.String_sqlip;
                mysqlhelperexImpl.DB_Database = comrcv.Struct_sqlinfo.String_sqlname;
                mysqlhelperexImpl.DB_Port = comrcv.Struct_sqlinfo.String_sqlport;
                mysqlhelperexImpl.DB_UserID = comrcv.Struct_sqlinfo.String_sqluser;
                //mysqlhelperexImpl.DB_Password = comrcv.Struct_sqlinfo.String_sqlpwd;
                mysqlhelperexImpl.DB_Password = MySqlPwd;
*/
                #endregion

                #region //获取最新版本信息

                string PathStr = "D://QGWuLiuService//PhoneApk//PhoneVersion.ini";
                csIniFiles CIni = new csIniFiles(PathStr);
                string thisversion = CIni.ReadString("VERSION", "Value", "1");
                string thisaddress = CIni.ReadString("ADDRESS", "Value", "1");

                string thisdefalut = CIni.ReadString("DEFAULT", "Value", "");
                string thisenableversion = CIni.ReadString("ENABLEVERSION", "Value", "");


                ret.Map_Args.Add("Version", thisversion);
                ret.Map_Args.Add("Address", thisaddress);

                ret.Map_Args.Add("Default", thisdefalut);
                ret.Map_Args.Add("Enableversion", thisenableversion);


                ret.Map_Args["ErrorMsg"] = "";
                ret.Byte_Flag = (sbyte)0;

                #endregion

            }
            catch
            {
            }

            return ret;
        }

        //验证IDKEY并返回登陆基础信息
        //返回null则说明无权限
        public static DataRow CheckNetIdkey(SqlInfo sqlmsg)
        {
            DataRow ret = null;

            #region //效验参数有效性

            if (sqlmsg == null)
            {
                return ret;
            }
            if (!(sqlmsg.__isset.string_sqlip && sqlmsg.__isset.string_sqlname && sqlmsg.__isset.string_sqlport
                    && sqlmsg.__isset.string_sqlpwd && sqlmsg.__isset.string_sqluser && sqlmsg.__isset.string_useridkey))
            {
                return ret;
            }

            #endregion

            #region //生成数据量连接信息

            MySqlHelperEx mysqlhelperexImpl = new MySqlHelperEx();
            mysqlhelperexImpl.DB_CharacterSet = "utf8";

            mysqlhelperexImpl.DB_Server = sqlmsg.String_sqlip;
            mysqlhelperexImpl.DB_Database = sqlmsg.String_sqlname;
            mysqlhelperexImpl.DB_Port = sqlmsg.String_sqlport;
            mysqlhelperexImpl.DB_UserID = sqlmsg.String_sqluser;
            //mysqlhelperexImpl.DB_Password = sqlmsg.String_sqlpwd;
            mysqlhelperexImpl.DB_Password = MySqlPwd;

            #endregion

            #region //1效验公司账号

            string commandText = string.Format("SELECT * FROM {0} WHERE Log_idkey = ?idkey;", "systemlogbiao");
            MySqlParameter[] msqlp = new MySqlParameter[1];
            msqlp[0] = new MySqlParameter("?idkey", sqlmsg.String_useridkey);

            ret = mysqlhelperexImpl.ExecuteDataRow(commandText, msqlp);

            #endregion

            return ret;
        }

        //手机登录
        public static ComThriftMsg Phone_LoginNew(string msg)
        {
            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;  //服务器异常
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            try
            {
                #region //反序列化

                byte[] bytrcv = Convert.FromBase64String(msg);
                ComThriftMsg comrcv = CommonTools.ByteTOComThriftAESD(bytrcv);

                int i = 0;
                if (comrcv.__isset.map_Args)
                {
                    foreach (string skey in comrcv.Map_Args.Keys)
                    {
                        bool find = true;
                        switch (skey)
                        {
                            case "Key_CompanyAcc":
                                break;
                            case "Key_NetAcc":
                                break;
                            case "Key_EmployeeAcc":
                                break;
                            case "Key_EmployeePwd":
                                break;
                            default:
                                find = false;
                                break;
                        }
                        if (find)
                        {
                            i++;
                        }
                    }
                }
                if (i != 4)
                {
                    ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                    return ret;
                }

                if (!comrcv.__isset.struct_sqlinfo)
                {
                    ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                    return ret;
                }
                else
                {
                    if (!(comrcv.Struct_sqlinfo.__isset.string_sqlip && comrcv.Struct_sqlinfo.__isset.string_sqlname && comrcv.Struct_sqlinfo.__isset.string_sqlport
                        && comrcv.Struct_sqlinfo.__isset.string_sqlpwd && comrcv.Struct_sqlinfo.__isset.string_sqluser))
                    {
                        ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                        return ret;
                    }
                }
                #endregion

                #region //生成数据量连接信息

                MySqlHelperEx mysqlhelperexImpl = new MySqlHelperEx();
                mysqlhelperexImpl.DB_CharacterSet = "utf8";

                mysqlhelperexImpl.DB_Server = comrcv.Struct_sqlinfo.String_sqlip;
                mysqlhelperexImpl.DB_Database = comrcv.Struct_sqlinfo.String_sqlname;
                mysqlhelperexImpl.DB_Port = comrcv.Struct_sqlinfo.String_sqlport;
                mysqlhelperexImpl.DB_UserID = comrcv.Struct_sqlinfo.String_sqluser;
                //mysqlhelperexImpl.DB_Password = comrcv.Struct_sqlinfo.String_sqlpwd;
                mysqlhelperexImpl.DB_Password = MySqlPwd;


                #endregion

                #region //效验权限

                #region //1效验公司账号
                string commandText = string.Format("SELECT * FROM user WHERE Account = ?companyAcc AND Status = '授权';");
                MySqlParameter[] msqlp = new MySqlParameter[1];
                msqlp[0] = new MySqlParameter("?companyAcc", comrcv.Map_Args["Key_CompanyAcc"]);

                DataRow sdr_company = mysqlhelperexImpl.ExecuteDataRow(commandText, msqlp);
                if (sdr_company == null)
                {
                    ret.Map_Args["ErrorMsg"] = "公司账号不存在";  //公司账号不存在
                    return ret;
                }

                #endregion

                #region //2效验网点账号
                commandText = string.Format("SELECT * FROM {0} WHERE Account = ?netAcc AND Fuser = ?companyAcc;", comrcv.Map_Args["Key_CompanyAcc"] + DOWNUSERBIAONAME);
                msqlp = new MySqlParameter[2];
                msqlp[0] = new MySqlParameter("?netAcc", comrcv.Map_Args["Key_NetAcc"]);
                msqlp[1] = new MySqlParameter("?companyAcc", comrcv.Map_Args["Key_CompanyAcc"]);

                DataRow sdr_net = mysqlhelperexImpl.ExecuteDataRow(commandText, msqlp);
                if (sdr_net == null)
                {
                    ret.Map_Args["ErrorMsg"] = "网点账号不存在";  //网点账号不存在
                    return ret;
                }

                #endregion

                #region //3效验员工账号
                commandText = string.Format("SELECT * FROM {0} WHERE  Account = ?employeeAcc;", comrcv.Map_Args["Key_CompanyAcc"] + EMPLOYEEBIAONAME);
                msqlp = new MySqlParameter[1];
        
                msqlp[0] = new MySqlParameter("?employeeAcc", comrcv.Map_Args["Key_EmployeeAcc"]);

                DataRow sdr_employee = mysqlhelperexImpl.ExecuteDataRow(commandText, msqlp);
                if (sdr_employee == null)
                {
                    ret.Map_Args["ErrorMsg"] = "员工账号不存在";  //员工账号不存在
                    return ret;
                }
                else
                {
                    if (sdr_employee["Password"].ToString() != comrcv.Map_Args["Key_EmployeePwd"].ToString())
                    {
                        ret.Map_Args["ErrorMsg"] = "员工密码错误";  //员工密码错误
                        return ret;
                    }
                    if (sdr_employee["Nets"].ToString() != "ALL" && !sdr_employee["Nets"].ToString().Contains(comrcv.Map_Args["Key_NetAcc"].ToString()))
                    {
                        ret.Map_Args["ErrorMsg"] = "员工无该网点权限";  //员工无该网点权限
                        return ret;
                    }
                }
                string ComCaiWu = "false";
                string NetCaiWu = "false";

                if (sdr_employee["Authority"].ToString() == "ALL")
                {
                    NetCaiWu = "true";
                }
                else
                {
                    if (sdr_employee["Authority"].ToString().IndexOf("财务中心") != -1)
                    {
                        NetCaiWu = "true";
                    }
                }
                if (sdr_employee["Companyauthority"].ToString().IndexOf("财务中心") != -1)
                {
                    ComCaiWu = "true";
                }
                #endregion

                #endregion

                #region //更新登陆数据库

                string idkeystr = Guid.NewGuid().ToString();

                try
                {
                    using (TransactionScope ts = new TransactionScope())
                    {
                        using (MySqlConnection con = new MySqlConnection(mysqlhelperexImpl.GetConnectStr()))
                        {
                            con.Open();

                            commandText = string.Format("SELECT * FROM {0} WHERE Log_companyaccount = ?companyAcc AND Log_ygaccount = ?employeeAcc AND Log_status = ?status;", "systemlogbiao");
                            msqlp = new MySqlParameter[3];
                            msqlp[0] = new MySqlParameter("?companyAcc", comrcv.Map_Args["Key_CompanyAcc"]);
                            msqlp[1] = new MySqlParameter("?employeeAcc", comrcv.Map_Args["Key_EmployeeAcc"]);
                            msqlp[2] = new MySqlParameter("?status", "3");  //1网点 2公司 3手机

                            DataRow sdr_syslog = mysqlhelperexImpl.ExecuteDataRow(con, commandText, msqlp);
                            if (sdr_syslog == null)
                            {
                                //新增登陆记录
                                commandText = string.Format("INSERT INTO {0} VALUES(NULL, " +
                                " ?idkey, ?companyname, ?companyaccount, ?netname, ?netaccount, ?ygname, ?ygaccount, ?status, ?time, ?device, ?default);", "systemlogbiao");
                                msqlp = new MySqlParameter[11];
                                msqlp[0] = new MySqlParameter("?idkey", idkeystr);
                                msqlp[1] = new MySqlParameter("?companyname", sdr_company["Name"].ToString());
                                msqlp[2] = new MySqlParameter("?companyaccount", sdr_company["Account"].ToString());
                                msqlp[3] = new MySqlParameter("?netname", sdr_net["Name"].ToString());
                                msqlp[4] = new MySqlParameter("?netaccount", sdr_net["Account"].ToString());
                                msqlp[5] = new MySqlParameter("?ygname", sdr_employee["Name"].ToString());
                                msqlp[6] = new MySqlParameter("?ygaccount", sdr_employee["Account"].ToString());
                                msqlp[7] = new MySqlParameter("?status", "3");  //1网点 2公司 3手机
                                msqlp[8] = new MySqlParameter("?time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                                msqlp[9] = new MySqlParameter("?device", "手机");
                                msqlp[10] = new MySqlParameter("?default", "");

                                int exeret = mysqlhelperexImpl.ExecuteNonQuery(con, commandText, msqlp);
                                if (exeret != 1)
                                {
                                    //新增登陆记录失败
                                    ret.Map_Args["ErrorMsg"] = "新增登陆记录失败";  //新增登陆记录失败
                                    return ret;
                                }
                            }
                            else
                            {
                                //新增登陆记录
                                commandText = string.Format("UPDATE {0} SET Log_idkey = ?idkey, Log_netname = ?netname, Log_netaccount = ?netAcc, Log_time = ?time WHERE Sid = ?sid;", "systemlogbiao");
                                msqlp = new MySqlParameter[5];
                                msqlp[0] = new MySqlParameter("?idkey", idkeystr);
                                msqlp[1] = new MySqlParameter("?netname", sdr_net["Name"].ToString());
                                msqlp[2] = new MySqlParameter("?netAcc", comrcv.Map_Args["Key_NetAcc"]);
                                msqlp[3] = new MySqlParameter("?time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                                msqlp[4] = new MySqlParameter("?sid", sdr_syslog["Sid"].ToString());

                                int exeret = mysqlhelperexImpl.ExecuteNonQuery(con, commandText, msqlp);
                                if (exeret != 1)
                                {
                                    //更新登陆记录失败
                                    ret.Map_Args["ErrorMsg"] = "更新登陆记录失败";  //更新登陆记录失败
                                    return ret;
                                }
                            }
                        }
                        ts.Complete();
                    }
                }
                catch (System.Exception e)
                {
                    ret.Map_Args["ErrorMsg"] = e.Message;
                    return ret;
                }

                #endregion

                #region //组装返回值

                ret.Map_Args.Add("ComCaiWu", ComCaiWu);
                ret.Map_Args.Add("NetCaiWu", NetCaiWu);
                ret.Map_Args.Add("IdKey", idkeystr);
                ret.Map_Args["ErrorMsg"] = "";
                ret.Byte_Flag = (sbyte)0;  //正常有效返回

                #endregion
            }
            catch
            {
            }

            return ret;
        }

        //手机批量提交运单
        public static ComThriftMsg Phone_UpLoadGoodsBatch(string msg)
        {
 
            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            try
            {
                #region //反序列化

                byte[] bytrcv = Convert.FromBase64String(msg);
                ComThriftMsg comrcv = CommonTools.ByteTOComThriftAESD_Decr(bytrcv);

                if (!comrcv.__isset.struct_sqlinfo)
                {
                    ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                    return ret;
                }
                else
                {
                    if (!(comrcv.Struct_sqlinfo.__isset.string_sqlip && comrcv.Struct_sqlinfo.__isset.string_sqlname && comrcv.Struct_sqlinfo.__isset.string_sqlport
                        && comrcv.Struct_sqlinfo.__isset.string_sqlpwd && comrcv.Struct_sqlinfo.__isset.string_sqluser && comrcv.Struct_sqlinfo.__isset.string_useridkey))
                    {
                        ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                        return ret;
                    }
                }
                #endregion

                #region //效验IDkey

                DataRow dr_loginfo = CheckNetIdkey(comrcv.Struct_sqlinfo);
                if (dr_loginfo == null)
                {
                    ret.Byte_Flag = (sbyte)-2;
                    ret.Map_Args["ErrorMsg"] = "IDKey无效";
                    return ret;
                }
                string loginfo = string.Format("Sid={0};Log_idkey={1};Log_companyname={2};Log_companyaccount={3};Log_netname={4};" +
                    "Log_netaccount={5};Log_ygname={6};Log_ygaccount={7};Log_status={8};Log_time={9};Log_device={10};Log_default={11}"
                    , dr_loginfo["Sid"].ToString(), dr_loginfo["Log_idkey"].ToString(), dr_loginfo["Log_companyname"].ToString()
                    , dr_loginfo["Log_companyaccount"].ToString(), dr_loginfo["Log_netname"].ToString(), dr_loginfo["Log_netaccount"].ToString()
                    , dr_loginfo["Log_ygname"].ToString(), dr_loginfo["Log_ygaccount"].ToString(), dr_loginfo["Log_status"].ToString()
                    , dr_loginfo["Log_time"].ToString(), dr_loginfo["Log_device"].ToString(), dr_loginfo["Log_default"].ToString());
               // logData.Info(loginfo);
             //   logData.Info(msg);

                #endregion
                ILog logJieKou = LogManager.GetLogger("LoggerJieKou");
                logJieKou.Info("手机批量提交运单" + "-" + dr_loginfo["Log_companyname"].ToString() + "-" + dr_loginfo["Log_netname"].ToString());
                #region //生成数据量连接信息

                MySqlHelperEx mysqlhelperexImpl = new MySqlHelperEx();
                mysqlhelperexImpl.DB_CharacterSet = "utf8";

                mysqlhelperexImpl.DB_Server = comrcv.Struct_sqlinfo.String_sqlip;
                mysqlhelperexImpl.DB_Database = comrcv.Struct_sqlinfo.String_sqlname;
                mysqlhelperexImpl.DB_Port = comrcv.Struct_sqlinfo.String_sqlport;
                mysqlhelperexImpl.DB_UserID = comrcv.Struct_sqlinfo.String_sqluser;
                //mysqlhelperexImpl.DB_Password = comrcv.Struct_sqlinfo.String_sqlpwd;
                mysqlhelperexImpl.DB_Password = MySqlPwd;

                #endregion

                #region //数据库事务批量增加运单

                ret = ExecuteInsertTransaction(mysqlhelperexImpl.GetConnectStr(), dr_loginfo["Log_companyaccount"].ToString(), comrcv);
                GC.Collect();
                GC.WaitForPendingFinalizers();

                #endregion

            }
            catch
            {
            }

            return ret;
        }


        //传化手机批量提交运单
        public static ComThriftMsg Phone_CH_UpLoadGoodsBatch(string msg)
        {

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            try
            {
                byte[] bytrcv = Convert.FromBase64String(msg);
                ComThriftMsg comrcv = CommonTools.ByteTOComThriftAESD_Decr(bytrcv);

                #region //效验IDkey

                DataRow dr_loginfo = CheckNetIdkey(comrcv.Struct_sqlinfo);
                if (dr_loginfo == null)
                {
                    ret.Byte_Flag = (sbyte)-2;
                    ret.Map_Args["ErrorMsg"] = "IDKey无效";
                    return ret;
                }
                string loginfo = string.Format("Sid={0};Log_idkey={1};Log_companyname={2};Log_companyaccount={3};Log_netname={4};" +
                    "Log_netaccount={5};Log_ygname={6};Log_ygaccount={7};Log_status={8};Log_time={9};Log_device={10};Log_default={11}"
                    , dr_loginfo["Sid"].ToString(), dr_loginfo["Log_idkey"].ToString(), dr_loginfo["Log_companyname"].ToString()
                    , dr_loginfo["Log_companyaccount"].ToString(), dr_loginfo["Log_netname"].ToString(), dr_loginfo["Log_netaccount"].ToString()
                    , dr_loginfo["Log_ygname"].ToString(), dr_loginfo["Log_ygaccount"].ToString(), dr_loginfo["Log_status"].ToString()
                    , dr_loginfo["Log_time"].ToString(), dr_loginfo["Log_device"].ToString(), dr_loginfo["Log_default"].ToString());
                // logData.Info(loginfo);
                //   logData.Info(msg);

                #endregion
                ILog logJieKou = LogManager.GetLogger("LoggerJieKou");
                logJieKou.Info("手机批量提交运单" + "-" + dr_loginfo["Log_companyname"].ToString() + "-" + dr_loginfo["Log_netname"].ToString());

                #region //生成数据量连接信息

                MySqlHelperEx mysqlhelperexImpl = new MySqlHelperEx();
                mysqlhelperexImpl.DB_CharacterSet = "utf8";

                mysqlhelperexImpl.DB_Server = comrcv.Struct_sqlinfo.String_sqlip;
                mysqlhelperexImpl.DB_Database = comrcv.Struct_sqlinfo.String_sqlname;
                mysqlhelperexImpl.DB_Port = comrcv.Struct_sqlinfo.String_sqlport;
                mysqlhelperexImpl.DB_UserID = comrcv.Struct_sqlinfo.String_sqluser;
                //mysqlhelperexImpl.DB_Password = comrcv.Struct_sqlinfo.String_sqlpwd;
                mysqlhelperexImpl.DB_Password = MySqlPwd;

                #endregion

                #region //数据库事务批量增加运单

                ret = ExecuteInsertTransaction(mysqlhelperexImpl.GetConnectStr(), dr_loginfo["Log_companyaccount"].ToString(), comrcv);

                GC.Collect();
                GC.WaitForPendingFinalizers();

                /*
                if (ret.Byte_Flag == 0)
                {
                    string biaoid = "";
                    foreach (Dictionary<string, string> argmapup in comrcv.List_MapArgs)
                    {
                        biaoid += argmapup["waybill_num"] + ",";
                    }
                    ChuanHuaTools.SendChuanHuaNew(biaoid, dr_loginfo["Log_companyaccount"].ToString());
                }
                */
      

                #endregion

            }
            catch
            {
            }

            return ret;
        }

        #region 手机批量提交运单相关事务

        private static MySqlParameter[] GetMySqlParameters(Dictionary<string, string> argmap, bool isdel)
        {
            bool haveTJ = false;
            bool haveZL = false;
            if (argmap == null)
            {
                return null;
            }
            if (argmap.Keys.Count < 50)
            {
                return null;
            }
            MySqlParameter[] ret = new MySqlParameter[70];
            int i = 0;
            foreach (string argkey in argmap.Keys)
            {
                bool needadd = true;
                switch (argkey)
                {
                    case "company_account":                     //公司名
                        ret[i] = new MySqlParameter("?Companyaccount", argmap[argkey]);
                        break;
                    case "waybill_from_acount":                 //建单网点账号
                        ret[i] = new MySqlParameter("?Createaccount", argmap[argkey]);
                        break;
                    case "waybill_to_acount":                   //收单网点账号
                        ret[i] = new MySqlParameter("?Foraccount", argmap[argkey]);
                        break;
                    case "goods_Title":                         //运单标题
                        ret[i] = new MySqlParameter("?Title", argmap[argkey]);
                        break;
                    case "waybill_num":                         //运单号
                        ret[i] = new MySqlParameter("?Id", argmap[argkey]);
                        break;
                    case "goods_num":                           //货号
                        ret[i] = new MySqlParameter("?Number", argmap[argkey]);
                        break;
                    case "waybill_from":                        //出港网点名
                        ret[i] = new MySqlParameter("?Sendplace", argmap[argkey]);
                        break;
                    case "waybill_to":                          //到港网点名
                        ret[i] = new MySqlParameter("?Fromplace", argmap[argkey]);
                        break;
                    case "Consignor":                           //发货人
                        ret[i] = new MySqlParameter("?Sender", argmap[argkey]);
                        break;
                    case "Consignor_phone":                     //发货人电话
                        ret[i] = new MySqlParameter("?Sendertelephone", argmap[argkey]);
                        break;
                    case "Consignee":                           //收货人
                        ret[i] = new MySqlParameter("?Fromer", argmap[argkey]);
                        break;
                    case "Delivery_address":                    //收货人地址
                        ret[i] = new MySqlParameter("?Fromeraddress", argmap[argkey]);
                        break;
                    case "Consignee_phone":                     //收货人电话
                        ret[i] = new MySqlParameter("?Fromerphone", argmap[argkey]);
                        break;
                    case "Consignee_mobile":                    //收货人手机
                        ret[i] = new MySqlParameter("?Fromertelephone", argmap[argkey]);
                        break;
                    case "Goods_Name":                          //货名
                        ret[i] = new MySqlParameter("?Goodsname", argmap[argkey]);
                        break;
                    case "Goods_Number":                        //货物数量      ------------------------
                        ret[i] = new MySqlParameter("?Goodsallcount", argmap[argkey]);
                        i++;
                        ret[i] = new MySqlParameter("?Goodscount", argmap[argkey]);
                        break;
                    case "Goods_Pack":                          //货物包装
                        ret[i] = new MySqlParameter("?Goodspack", argmap[argkey]);
                        break;
                    case "tran_fei":                            //运输费用
                        ret[i] = new MySqlParameter("?Goodsyuncost", argmap[argkey]);
                        break;
                    case "The_cod":                             //代收货款
                        ret[i] = new MySqlParameter("?Goodsdaishou", argmap[argkey]);
                        break;
                    case "Insured_transport_fei":               //保价费用
                        ret[i] = new MySqlParameter("?Goodsbaocost", argmap[argkey]);
                        break;
                    case "Insured_transport_jine":              //保价金额
                        ret[i] = new MySqlParameter("?Goodspeicost", argmap[argkey]);
                        break;
                    case "Aggregate_expenses":                  //合计费用
                        ret[i] = new MySqlParameter("?Goodsallcost", argmap[argkey]);
                        break;
                    case "Goods_Service":                       //货运服务
                        ret[i] = new MySqlParameter("?Goodsservice", argmap[argkey]);
                        break;
                    case "Additional_treaty":                   //附加特约
                        ret[i] = new MySqlParameter("?Goodsfujiashuoming", argmap[argkey]);
                        break;
                    case "Pickups_address":                     //取货地址
                        ret[i] = new MySqlParameter("?Goodsgetaddress", argmap[argkey]);
                        break;
                    case "Query_suggestion":                    //查询投诉电话
                        ret[i] = new MySqlParameter("?Toushuphone", argmap[argkey]);
                        break;
                    case "kaipiaoTime":                         //开票日期
                        ret[i] = new MySqlParameter("?Time", argmap[argkey]);
                        break;
                    case "TranAccount":                         //中转地点账号
                        ret[i] = new MySqlParameter("?Zhuanaccount", argmap[argkey]);
                        break;
                    case "TransName":                           //中转地点网点名
                        ret[i] = new MySqlParameter("?Zhuanname", argmap[argkey]);
                        break;
                    case "XianFu":                              //现付      ------------------------
                        ret[i] = new MySqlParameter("?Goodsxianfucost", argmap[argkey]);
                        i++;
                        ret[i] = new MySqlParameter("?Goodspaycost", argmap[argkey]);
                        break;
                    case "Huifu":                               //回付
                        ret[i] = new MySqlParameter("?Goodshuifucost", argmap[argkey]);
                        break;
                    case "Tifu":                                //提付
                        ret[i] = new MySqlParameter("?Goodstifucost", argmap[argkey]);
                        break;
                    case "pay_meth":                            //付费方式
                        ret[i] = new MySqlParameter("?Goodspayway", argmap[argkey]);
                        break;
                    case "JieHuo_Fei":                          //接货费
                        ret[i] = new MySqlParameter("?Goodsjiecost", argmap[argkey]);
                        break;
                    case "SongHuo_Fei":                         //送货费
                        ret[i] = new MySqlParameter("?Goodssongcost", argmap[argkey]);
                        break;
                    case "ChaDiao_Fei":                         //叉掉费
                        ret[i] = new MySqlParameter("?Goodschachecost", argmap[argkey]);
                        break;
                    case "BaoZhuang_Fei":                       //包装费
                        ret[i] = new MySqlParameter("?Goodsbaozhuangcost", argmap[argkey]);
                        break;
                    case "DaiBan_Fei":                          //代办费
                        ret[i] = new MySqlParameter("?Goodsdaibancost", argmap[argkey]);
                        break;
                    case "Duanxin_Fei":                         //短信费
                        ret[i] = new MySqlParameter("?Goodsduanxincost", argmap[argkey]);
                        break;
                    case "Huikou_YiFei":                        //回扣已付
                        ret[i] = new MySqlParameter("?Goodstuoyicost", argmap[argkey]);
                        break;
                    case "Huikou_WeiFei":                       //回扣未付
                        ret[i] = new MySqlParameter("?Goodstuoweicost", argmap[argkey]);
                        break;
                    case "DianFu_Fei":                          //垫付费
                        ret[i] = new MySqlParameter("?Goodszhuanyicost", argmap[argkey]);
                        break;
                    case "FenBo_Fei":                           //分拨费
                        ret[i] = new MySqlParameter("?Goodszhuanweicost", argmap[argkey]);
                        break;
                    case "ChuGangCangChu_Fei":                  //出港仓储费
                        ret[i] = new MySqlParameter("?Goodschucangcost", argmap[argkey]);
                        break;
                    case "DaoGangCangChu_Fei":                  //到港仓储费
                        ret[i] = new MySqlParameter("?Goodsdaocangcost", argmap[argkey]);
                        break;
                    case "ShouHuo_YueJie":                      //收货月结
                        ret[i] = new MySqlParameter("?Goodsshouyuecost", argmap[argkey]);
                        break;
                    case "FaHuo_YueJie":                        //发货月结
                        ret[i] = new MySqlParameter("?Goodsfayuecost", argmap[argkey]);
                        break;
                    case "chengyunpeople":                      //承运经办人
                        ret[i] = new MySqlParameter("?Worker", argmap[argkey]);
                        break;
                    case "Other_Fei":                           //其它费
                        ret[i] = new MySqlParameter("?Goodsothercost", argmap[argkey]);
                        break;
                    case "Other_Fei_Meth":                      //其它费说明
                        ret[i] = new MySqlParameter("?Goodsothercostshuoming", argmap[argkey]);
                        break;
                    case "Volume":                              //体积
                        ret[i] = new MySqlParameter("?Goodstiji", argmap[argkey]);
                        haveTJ = true;
                        break;
                    case "Weight":                              //重量
                        ret[i] = new MySqlParameter("?Goodsweight", argmap[argkey]);
                        haveZL = true;
                        break;
                    default:
                        needadd = false;
                        break;
                }
                if (needadd)
                {
                    i++;
                }

            }

            //判断所需参数是否完全为所传参数的子集
            if ((i != 52) && (i != 54))
            {
                return null;
            }

            if (isdel && (!argmap.Keys.Contains("DeleteTime")))
            {
                return null;
            }

            if (argmap.Keys.Contains("TranAccount") && argmap.Keys.Contains("TransName"))
            {
                string zzType = "0";
                if (argmap["TransName"] != "")
                {
                    if (argmap["TranAccount"] != "")
                    {
                        zzType = "1";   //内转
                    }
                    else
                    {
                        zzType = "2";   //外转
                    }
                }
                ret[i] = new MySqlParameter("?Zhuantype", zzType);  //转运类型
                i++;
            }
            else
            {
                return null;
            }

            //-------------------------------------  其他默认值
            ret[i] = new MySqlParameter("?Passplace", "");          //转运中转地
            i++;
            ret[i] = new MySqlParameter("?Senderbank", "");         //发货人账号
            i++;
            if (!haveTJ)
            {
                ret[i] = new MySqlParameter("?Goodstiji", "");          //货物体积
                i++;
            }
            if (!haveZL)
            {
                ret[i] = new MySqlParameter("?Goodsweight", "");        //货物重量
                i++;
            }
            //ret[i] = new MySqlParameter("?Goodstiji", "");          //货物体积
            //i++;
            //ret[i] = new MySqlParameter("?Goodsweight", "");        //货物重量
            //i++;
            ret[i] = new MySqlParameter("?Goodspeifucost", "0");    //货物赔偿金额
            i++;
            ret[i] = new MySqlParameter("?Machine", "手持");        //开票设备类型
            i++;
            ret[i] = new MySqlParameter("?Status", isdel ? "删除" : "新单");         //运单状态
            i++;
            ret[i] = new MySqlParameter("?Isshou", "0");            //是否自录单号
            i++;
            ret[i] = new MySqlParameter("?Ischai", "否");           //是否拆分
            i++;
            ret[i] = new MySqlParameter("?Carsendid", "");          //发车车次号
            i++;
            ret[i] = new MySqlParameter("?Daogangtime", "");        //到港时间
            i++;
            ret[i] = new MySqlParameter("?Qianshou", "");           //签收人
            i++;
            ret[i] = new MySqlParameter("?Qianshouphone", "");      //签收人电话
            i++;
            ret[i] = new MySqlParameter("?Qianshouid", "");         //签收人身份证号
            i++;
            ret[i] = new MySqlParameter("?Qianshoutime", "");       //签收时间
            i++;
            ret[i] = new MySqlParameter("?Qianshoudefault", "");    //签收说明
            i++;
            ret[i] = new MySqlParameter("?Default", "");            //运单说明
            i++;
            //-------------------------------------

            return ret;

        }


        private static MySqlParameter[] GetMySqlParametersDS(Dictionary<string, string> argmap)
        {
            if (argmap == null)
            {
                return null;
            }
            if (argmap.Keys.Count < 50)
            {
                return null;
            }
            MySqlParameter[] ret = new MySqlParameter[29];
            int i = 0;
            foreach (string argkey in argmap.Keys)
            {
                bool needadd = true;
                switch (argkey)
                {
                    case "waybill_from_acount":                 //建单网点账号
                        ret[i] = new MySqlParameter("?Createaccount", argmap[argkey]);
                        break;
                    case "waybill_to_acount":                   //收单网点账号
                        ret[i] = new MySqlParameter("?Foraccount", argmap[argkey]);
                        break;
                    case "waybill_num":                         //运单号
                        ret[i] = new MySqlParameter("?Id", argmap[argkey]);
                        break;
                    case "goods_num":                           //货号
                        ret[i] = new MySqlParameter("?Number", argmap[argkey]);
                        break;
                    case "kaipiaoTime":                         //开票日期
                        ret[i] = new MySqlParameter("?Time", argmap[argkey]);
                        break;
                    case "waybill_from":                        //出港网点名
                        ret[i] = new MySqlParameter("?Sendplace", argmap[argkey]);
                        break;
                    case "waybill_to":                          //到港网点名
                        ret[i] = new MySqlParameter("?Fromplace", argmap[argkey]);
                        break;
                    case "Consignor":                           //发货人
                        ret[i] = new MySqlParameter("?Sender", argmap[argkey]);
                        break;
                    case "Consignor_phone":                     //发货人电话
                        ret[i] = new MySqlParameter("?Senderphone", argmap[argkey]);
                        break;
                    case "Consignee":                           //收货人
                        ret[i] = new MySqlParameter("?Fromer", argmap[argkey]);
                        break;
                    case "Consignee_mobile":                    //收货人手机
                        ret[i] = new MySqlParameter("?Fromerphone", argmap[argkey]);
                        break;
                    case "Goods_Name":                          //货名
                        ret[i] = new MySqlParameter("?Goodsname", argmap[argkey]);
                        break;
                    case "Goods_Number":                        //货物数量
                        ret[i] = new MySqlParameter("?Goodscount", argmap[argkey]);
                        break;
                    case "pay_meth":                            //付费方式
                        ret[i] = new MySqlParameter("?Goodspayway", argmap[argkey]);
                        break;
                    case "Goods_Service":                       //货运服务
                        ret[i] = new MySqlParameter("?Goodsservice", argmap[argkey]);
                        break;
                    case "The_cod":                             //代收货款-------预计应收代收款
                        ret[i] = new MySqlParameter("?YushouData", argmap[argkey]);
                        break;
                    default:
                        needadd = false;
                        break;
                }
                if (needadd)
                {
                    i++;
                }
            }

            //判断所需参数是否完全为所传参数的子集
            if (i != 16)
            {
                return null;
            }

            //-------------------------------------  其他默认值
            ret[i] = new MySqlParameter("?ShishouData", "0");       //实收代收款
            i++;
            ret[i] = new MySqlParameter("?ShouxuData", "0");        //手续费
            i++;
            ret[i] = new MySqlParameter("?ShifuData", "0");         //实付款
            i++;
            ret[i] = new MySqlParameter("?Status", "新代收");       //代收款状态
            i++;
            ret[i] = new MySqlParameter("?YishouData", "0");        //收款时间
            i++;
            ret[i] = new MySqlParameter("?DakuanData", "0");        //回款批次号
            i++;
            ret[i] = new MySqlParameter("?DaozhangData", "0");      //到账时间
            i++;
            ret[i] = new MySqlParameter("?HuanpiaoData", "0");      //换票批次号
            i++;
            ret[i] = new MySqlParameter("?FukuanData", "0");        //付款批次号
            i++;
            ret[i] = new MySqlParameter("?FukuanRen", "0");         //付款人
            i++;
            ret[i] = new MySqlParameter("?FukuanPhone", "0");       //付款人电话
            i++;
            ret[i] = new MySqlParameter("?FukuanShuoming", "0");    //付款说明
            i++;
            ret[i] = new MySqlParameter("?Default", "0");           //付款其他说明
            i++;
            //-------------------------------------

            return ret;
        }


        private static MySqlParameter[] GetMySqlParametersRC(Dictionary<string, string> argmap, bool isdel)
        {
            if (argmap == null)
            {
                return null;
            }
            if (argmap.Keys.Count < 50)
            {
                return null;
            }
            if (isdel && (!argmap.Keys.Contains("DeleteTime")))
            {
                return null;
            }
            MySqlParameter[] ret = new MySqlParameter[8];
            int i = 0;
            foreach (string argkey in argmap.Keys)
            {
                bool needadd = true;
                switch (argkey)
                {
                    case "waybill_from_acount":                 //建单网点账号  ----操作网点账号
                        ret[i] = new MySqlParameter("?Doaccount", argmap[argkey]);
                        break;
                    case "waybill_from":                        //出港网点名    ----操作网点名
                        ret[i] = new MySqlParameter("?Doname", argmap[argkey]);
                        break;
                    case "waybill_num":                         //运单号
                        ret[i] = new MySqlParameter("?Id", argmap[argkey]);
                        break;
                    case "kaipiaoTime":                         //开票日期      ----操作时间
                        if (!isdel)
                        {
                            //ret[i] = new MySqlParameter("?Times", argmap[argkey]);
                            ret[i] = new MySqlParameter("?Times", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                        }
                        else
                        {
                            ret[i] = new MySqlParameter("?Times", argmap["DeleteTime"]);
                        }
                        break;
                    case "chengyunpeople":                      //承运经办人
                        ret[i] = new MySqlParameter("?Worker", argmap[argkey]);
                        break;
                    case "The_cod":                             //代收货款
                        if (!isdel)
                        {
                            if ((argmap["The_cod"] == "0") || (argmap["The_cod"] == ""))
                            {
                                ret[i] = new MySqlParameter("?Status", "新单");         //运单状态描述
                            }
                            else
                            {
                                ret[i] = new MySqlParameter("?Status", "新单+新代收");  //运单状态描述
                            }
                        }
                        else
                        {
                            ret[i] = new MySqlParameter("?Status", "删除运单");         //运单状态描述
                        }
                        break;
                    case "Good_Default":                      //备注
                        ret[i] = new MySqlParameter("?Default", argmap[argkey]);
                        break;
                    default:
                        needadd = false;
                        break;
                }
                if (needadd)
                {
                    i++;
                }
            }

            //判断所需参数是否完全为所传参数的子集
            
            if (i != 6&&i!=7)
            {
                return null;
            }

            //-------------------------------------  其他默认值
            ret[i] = new MySqlParameter("?Machine", "手持");        //操作设备类型
            i++;
            if (argmap.Keys.Contains("Good_Default") == false)
            {
                ret[i] = new MySqlParameter("?Default", "");            //操作说明
                i++;
            }
            //-------------------------------------

            return ret;
        }


        //return:
        //      Byte_Flag                           0有效返回  -1参数错误  -2服务器数据库连接错误
        //      Map_Args.Key="SCount"               成功总条数Key建
        //      Map_Args["SCount"]                  成功总条数
        //      Map_Args.Key="DFCount"              失败总条数Key建
        //      Map_Args["DFCount"]                 失败总条数
        //      Map_Args.Key                        运单号
        //      Map_Args.value                      i服务器异常导致操作未执行该运单需重发   
        //                                          e该运单参数错误
        //                                          a该运单为重票
        //                                          f插入运单时数据库操作错误
        //                                          s新增运单成功
        private static ComThriftMsg ExecuteInsertTransaction(string connectionString, string CompanyAcc, ComThriftMsg comtmsg)
        {
            ILog logRecode = LogManager.GetLogger("LoggerRecod");
            logRecode.Info("0");

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            if (comtmsg == null)
            {
                logRecode.Info("参数错误或无效");
                //参数错误
                ret.Map_Args["ErrorMsg"] = "参数错误或无效";
                return ret;
            }

            ret.Map_Args = new Dictionary<string, string>();

            if (comtmsg.__isset.list_MapArgs)
            {
                int normalCount = 0;
                ret.Map_Args["SCount"] = "0";

                //ret.Map_Args["DFCount"] = comtmsg.List_MapArgs.Count.ToString();

                foreach (Dictionary<string, string> argmap in comtmsg.List_MapArgs)
                {
                    if (argmap.Keys.Contains("waybill_num"))
                    {
                        ret.Map_Args[argmap["waybill_num"]] = "i";  //未执行
                    }
                    if (argmap.Keys.Contains("DeleteTime") && (argmap["DeleteTime"] == ""))
                    {
                        normalCount++;
                    }
                }
                //统计正常运单数量
                ret.Map_Args["DFCount"] = normalCount.ToString();

                //日志输出
                string logmsg = string.Format("{0}:提交{1}票", CompanyAcc, normalCount.ToString());
                logRecode.Info(logmsg);
            }
            else
            {
                logRecode.Info("提交内容中没有运单");

                ret.Map_Args["SCount"] = "0";
                ret.Map_Args["DFCount"] = "0";
                ret.Map_Args["ErrorMsg"] = "";  //有效返回
                ret.Byte_Flag = (sbyte)0;
                return ret;
            }

            try
            {
              //  string commandSelectText = string.Format("SELECT Biao_Id, Biao_Time, Biao_Worker FROM {0} WHERE Biao_Id = ?Biao_Id UNION   SELECT Biao_Id, Biao_Time, Biao_Worker FROM {1} WHERE  Biao_Id = ?Biao_Id;", CompanyAcc + GOODSBIAONAME, CompanyAcc + OVERGOODSBIAONAME);
                MySqlParameter[] commandSelectParameters = new MySqlParameter[1];
                commandSelectParameters[0] = new MySqlParameter("?Biao_Id", "");

                string commandInsertText = string.Format("INSERT INTO {0}( " +
                    " Biao_Createaccount, Biao_Foraccount, Biao_Companyaccount, Biao_Title, Biao_Id, Biao_Number, Biao_Time, Biao_Sendplace, Biao_Fromplace, Biao_Passplace," +
                    " Biao_Sender, Biao_Senderbank, Biao_Sendertelephone, Biao_Fromer, Biao_Fromerphone, Biao_Fromertelephone, Biao_Fromeraddress, Biao_Goodsname, Biao_Goodsallcount, Biao_Goodscount," +
                    " Biao_Goodspack, Biao_Goodstiji, Biao_Goodsweight, Biao_Goodspayway, Biao_Goodsservice, Biao_Goodsdaishou, Biao_Goodsxianfucost, Biao_Goodstifucost, Biao_Goodshuifucost, Biao_Goodsshouyuecost," +
                    " Biao_Goodsfayuecost, Biao_Goodsyuncost, Biao_Goodsjiecost, Biao_Goodssongcost, Biao_Goodschachecost, Biao_Goodsbaozhuangcost, Biao_Goodstuoyicost, Biao_Goodstuoweicost, Biao_Goodszhuanyicost, Biao_Goodszhuanweicost," +
                    " Biao_Goodsdaibancost, Biao_Goodsduanxincost, Biao_Goodschucangcost, Biao_Goodsdaocangcost, Biao_Goodsothercost, Biao_Goodsbaocost, Biao_Goodspeicost, Biao_Goodsallcost, Biao_Goodspaycost, Biao_Goodspeifucost," +
                    " Biao_Goodsothercostshuoming, Biao_Goodsgetaddress, Biao_Goodsfujiashuoming, Biao_Toushuphone, Biao_Worker, Biao_Machine, Biao_Status, Biao_Isshou, Biao_Ischai, Biao_Carsendid," +
                    " Biao_Zhuantype, Biao_Zhuanaccount, Biao_Zhuanname, Biao_Daogangtime, Biao_Qianshou, Biao_Qianshouphone, Biao_Qianshouid, Biao_Qianshoutime, Biao_Qianshoudefault, Biao_Default) VALUES ( " +
                    " ?Createaccount, ?Foraccount, ?Companyaccount, ?Title, ?Id, ?Number, ?Time, ?Sendplace, ?Fromplace, ?Passplace," +
                    " ?Sender, ?Senderbank, ?Sendertelephone, ?Fromer, ?Fromerphone, ?Fromertelephone, ?Fromeraddress, ?Goodsname, ?Goodsallcount, ?Goodscount," +
                    " ?Goodspack, ?Goodstiji, ?Goodsweight, ?Goodspayway, ?Goodsservice, ?Goodsdaishou, ?Goodsxianfucost, ?Goodstifucost, ?Goodshuifucost, ?Goodsshouyuecost," +
                    " ?Goodsfayuecost, ?Goodsyuncost, ?Goodsjiecost, ?Goodssongcost, ?Goodschachecost, ?Goodsbaozhuangcost, ?Goodstuoyicost, ?Goodstuoweicost, ?Goodszhuanyicost, ?Goodszhuanweicost," +
                    " ?Goodsdaibancost, ?Goodsduanxincost, ?Goodschucangcost, ?Goodsdaocangcost, ?Goodsothercost, ?Goodsbaocost, ?Goodspeicost, ?Goodsallcost, ?Goodspaycost, ?Goodspeifucost," +
                    " ?Goodsothercostshuoming, ?Goodsgetaddress, ?Goodsfujiashuoming, ?Toushuphone, ?Worker, ?Machine, ?Status, ?Isshou, ?Ischai, ?Carsendid," +
                    " ?Zhuantype, ?Zhuanaccount, ?Zhuanname, ?Daogangtime, ?Qianshou, ?Qianshouphone, ?Qianshouid, ?Qianshoutime, ?Qianshoudefault, ?Default);", CompanyAcc + GOODSBIAONAME);

                string commandInsertDelText = string.Format("INSERT INTO {0}( " +
                    " Biao_Createaccount, Biao_Foraccount, Biao_Companyaccount, Biao_Title, Biao_Id, Biao_Number, Biao_Time, Biao_Sendplace, Biao_Fromplace, Biao_Passplace," +
                    " Biao_Sender, Biao_Senderbank, Biao_Sendertelephone, Biao_Fromer, Biao_Fromerphone, Biao_Fromertelephone, Biao_Fromeraddress, Biao_Goodsname, Biao_Goodsallcount, Biao_Goodscount," +
                    " Biao_Goodspack, Biao_Goodstiji, Biao_Goodsweight, Biao_Goodspayway, Biao_Goodsservice, Biao_Goodsdaishou, Biao_Goodsxianfucost, Biao_Goodstifucost, Biao_Goodshuifucost, Biao_Goodsshouyuecost," +
                    " Biao_Goodsfayuecost, Biao_Goodsyuncost, Biao_Goodsjiecost, Biao_Goodssongcost, Biao_Goodschachecost, Biao_Goodsbaozhuangcost, Biao_Goodstuoyicost, Biao_Goodstuoweicost, Biao_Goodszhuanyicost, Biao_Goodszhuanweicost," +
                    " Biao_Goodsdaibancost, Biao_Goodsduanxincost, Biao_Goodschucangcost, Biao_Goodsdaocangcost, Biao_Goodsothercost, Biao_Goodsbaocost, Biao_Goodspeicost, Biao_Goodsallcost, Biao_Goodspaycost, Biao_Goodspeifucost," +
                    " Biao_Goodsothercostshuoming, Biao_Goodsgetaddress, Biao_Goodsfujiashuoming, Biao_Toushuphone, Biao_Worker, Biao_Machine, Biao_Status, Biao_Isshou, Biao_Ischai, Biao_Carsendid," +
                    " Biao_Zhuantype, Biao_Zhuanaccount, Biao_Zhuanname, Biao_Daogangtime, Biao_Qianshou, Biao_Qianshouphone, Biao_Qianshouid, Biao_Qianshoutime, Biao_Qianshoudefault, Biao_Default) VALUES ( " +
                    " ?Createaccount, ?Foraccount, ?Companyaccount, ?Title, ?Id, ?Number, ?Time, ?Sendplace, ?Fromplace, ?Passplace," +
                    " ?Sender, ?Senderbank, ?Sendertelephone, ?Fromer, ?Fromerphone, ?Fromertelephone, ?Fromeraddress, ?Goodsname, ?Goodsallcount, ?Goodscount," +
                    " ?Goodspack, ?Goodstiji, ?Goodsweight, ?Goodspayway, ?Goodsservice, ?Goodsdaishou, ?Goodsxianfucost, ?Goodstifucost, ?Goodshuifucost, ?Goodsshouyuecost," +
                    " ?Goodsfayuecost, ?Goodsyuncost, ?Goodsjiecost, ?Goodssongcost, ?Goodschachecost, ?Goodsbaozhuangcost, ?Goodstuoyicost, ?Goodstuoweicost, ?Goodszhuanyicost, ?Goodszhuanweicost," +
                    " ?Goodsdaibancost, ?Goodsduanxincost, ?Goodschucangcost, ?Goodsdaocangcost, ?Goodsothercost, ?Goodsbaocost, ?Goodspeicost, ?Goodsallcost, ?Goodspaycost, ?Goodspeifucost," +
                    " ?Goodsothercostshuoming, ?Goodsgetaddress, ?Goodsfujiashuoming, ?Toushuphone, ?Worker, ?Machine, ?Status, ?Isshou, ?Ischai, ?Carsendid," +
                    " ?Zhuantype, ?Zhuanaccount, ?Zhuanname, ?Daogangtime, ?Qianshou, ?Qianshouphone, ?Qianshouid, ?Qianshoutime, ?Qianshoudefault, ?Default);", CompanyAcc + DELGOODSBIAONAME);

                string commandInsertDSText = string.Format("INSERT INTO {0} VALUES (null, " +
                    " ?Createaccount, ?Foraccount, ?Id, ?Number, ?Time, ?Sendplace, ?Fromplace, ?Sender, ?Senderphone, ?Fromer," +
                    " ?Fromerphone, ?Goodsname, ?Goodscount, ?Goodspayway, ?Goodsservice, ?YushouData, ?ShishouData, ?ShouxuData, ?ShifuData, ?Status," +
                    " ?YishouData, ?DakuanData, ?DaozhangData, ?HuanpiaoData, ?FukuanData, ?FukuanRen, ?FukuanPhone, ?FukuanShuoming, ?Default);", CompanyAcc + DAISHOUBIAONAME);

                string commandInsertRCText = string.Format("INSERT INTO {0} VALUES (null, " +
                    " ?Doaccount, ?Doname, ?Id, ?Times, ?Status, ?Worker, ?Machine, ?Default);", CompanyAcc + LISTBIAONAME);

                MySqlHelperEx mysqlhelperexImpl = new MySqlHelperEx();

                //-----------------迭代、事务控制
                logRecode.Info("gogogo_1");
                int ttcount = comtmsg.List_MapArgs.Count;

                List<Dictionary<string, string>> temp_tslist = new List<Dictionary<string, string>>();
                //迭代所有运单
                foreach (Dictionary<string, string> argmapup in comtmsg.List_MapArgs)
                {
                    ttcount--;
                    temp_tslist.Add(argmapup);
                    if ((ttcount > 0) && (temp_tslist.Count < MAX_TS_COUNT))
                    {
                        continue;
                    }

                    logRecode.Info("gogogo_2 ttcount = " + ttcount.ToString());
                    try
                    {
                        using (TransactionScope tsone = new TransactionScope())
                        {
                        
                            using (MySqlConnection con = new MySqlConnection(connectionString))
                            {
                                con.Open();

                                #region 检查是否有重单
                                bool befirst = true;
                                string condition = "(";
                                foreach (Dictionary<string, string> argmap in temp_tslist)
                                {
                                    if (argmap["DeleteTime"] == "")
                                    {

                                        if (!befirst)
                                        {
                                            condition += ",";
                                        }
                                        else
                                        {
                                            befirst = false;
                                        }
                                        condition += "'" + argmap["waybill_num"] + "'";
                                    }
                                    
                                }
                                condition += ")";
                                logRecode.Info(condition);

                                string commandChongSelectText = string.Format("SELECT Biao_Id, Biao_Time, Biao_Worker FROM {0} WHERE Biao_Id IN {1} ;",
                                    CompanyAcc + GOODSBIAONAME, condition);

                                DataSet ds_ChongPiao = mysqlhelperexImpl.ExecuteDataset(con, commandChongSelectText);
                                if (ds_ChongPiao != null)
                                {
                                    DataTable dt_ChongPiao = ds_ChongPiao.Tables[0];
                                    if (dt_ChongPiao.Rows.Count != 0)
                                    {
                                        con.Close();
                                     
                                        int count = 0;
                                        foreach (System.Data.DataRow ChongPiaoRow in dt_ChongPiao.Rows)
                                        {
                                            foreach (Dictionary<string, string> argmap in temp_tslist)
                                            {
                                                if (ChongPiaoRow["Biao_Time"].ToString() == argmap["kaipiaoTime"] && ChongPiaoRow["Biao_Id"].ToString() == argmap["waybill_num"])
                                                {
                                                    ret.Map_Args[argmap["waybill_num"]] = "s";  //插入运单成功
                                                    count++;
                                                }
                                            }
                                        }
                                        if (count == 0)
                                        {
                                            ret.Map_Args["SCount"] = "0";
                                            ret.Map_Args["DFCount"] = "0";
                                            ret.Map_Args["ErrorMsg"] = "有重单";  //有效返回
                                            ret.Byte_Flag = (sbyte)-1;
                                            logRecode.Info("有重单,直接退出");
                                        }
                                        else
                                        {
                                            ret.Map_Args["SCount"] = count.ToString();
                                            ret.Map_Args["DFCount"] = "0";
                                            ret.Map_Args["ErrorMsg"] = "处理重复提交";  //有效返回
                                            ret.Byte_Flag = (sbyte)0;
                                            logRecode.Info(string.Format("有重单{0}条,判断为提交成功", count));
                                        }
                                        return ret;
                                    }
                                }
                                string starttime = (DateTime.Now.AddDays(-30)).ToString("yyyy-MM-dd");
                                commandChongSelectText = string.Format("SELECT Biao_Id, Biao_Time, Biao_Worker FROM {0} WHERE Biao_Time > '{1}' AND Biao_Id IN {2} ;",
                                    CompanyAcc + OVERGOODSBIAONAME, starttime, condition);

                                ds_ChongPiao = mysqlhelperexImpl.ExecuteDataset(con, commandChongSelectText);
                                if (ds_ChongPiao != null)
                                {
                                    DataTable dt_ChongPiao = ds_ChongPiao.Tables[0];
                                    if (dt_ChongPiao.Rows.Count != 0)
                                    {
                                        con.Close();

                                        int count = 0;
                                        foreach (System.Data.DataRow ChongPiaoRow in dt_ChongPiao.Rows)
                                        {
                                            foreach (Dictionary<string, string> argmap in temp_tslist)
                                            {
                                                if (ChongPiaoRow["Biao_Time"].ToString() == argmap["kaipiaoTime"] && ChongPiaoRow["Biao_Id"].ToString() == argmap["waybill_num"])
                                                {
                                                    ret.Map_Args[argmap["waybill_num"]] = "s";  //插入运单成功
                                                    count++;
                                                }
                                            }
                                        }
                                        if (count == 0)
                                        {
                                            ret.Map_Args["SCount"] = "0";
                                            ret.Map_Args["DFCount"] = "0";
                                            ret.Map_Args["ErrorMsg"] = "有重单";  //有效返回
                                            ret.Byte_Flag = (sbyte)-1;
                                            logRecode.Info("有重单,直接退出");
                                        }
                                        else
                                        {
                                            ret.Map_Args["SCount"] = count.ToString();
                                            ret.Map_Args["DFCount"] = "0";
                                            ret.Map_Args["ErrorMsg"] = "处理重复提交";  //有效返回
                                            ret.Byte_Flag = (sbyte)0;
                                            logRecode.Info(string.Format("有重单{0}条,判断为提交成功", count));
                                        }
                                        return ret;
                                    }
                                }








                                #endregion


                                #region //事务处理

                                foreach (Dictionary<string, string> argmap in temp_tslist)
                                {
                                    if (argmap.Keys.Contains("waybill_num") && argmap.Keys.Contains("DeleteTime"))
                                    {
                                        if (argmap["DeleteTime"] == "")
                                        {
                                            #region //正常新运单

                                            //插入新单
                                            MySqlParameter[] commandInsertParameters = GetMySqlParameters(argmap, false);
                                            if (commandInsertParameters == null)
                                            {
                                                logRecode.Info("1");
                                                ret.Map_Args[argmap["waybill_num"]] = "e";  //该运单参数错误
                                                continue;
                                            }
                                            int exret = MySqlHelper.ExecuteNonQuery(con, commandInsertText, commandInsertParameters);
                                            if (exret != 1)
                                            {
                                                logRecode.Info("2");
                                                ret.Map_Args[argmap["waybill_num"]] = "f";  //该运单插入数据库错误
                                                continue;
                                            }



                                            //插入新操作记录
                                            MySqlParameter[] commandInsertRCParameters = GetMySqlParametersRC(argmap, false);
                                            if (commandInsertRCParameters == null)
                                            {
                                                logRecode.Info("4");
                                                ret.Map_Args[argmap["waybill_num"]] = "e";  //该运单参数错误
                                                continue;
                                            }
                                            exret = MySqlHelper.ExecuteNonQuery(con, commandInsertRCText, commandInsertRCParameters);
                                            if (exret != 1)
                                            {
                                                logRecode.Info("5");
                                                ret.Map_Args[argmap["waybill_num"]] = "f";  //该运单插入数据库错误
                                                continue;
                                            }


                                            if (argmap.Keys.Contains("The_cod") && (argmap["The_cod"] != "0") && (argmap["The_cod"] != ""))
                                            {
                                                //插入新代收

                                                MySqlParameter[] commandInsertDSParameters = GetMySqlParametersDS(argmap);
                                                if (commandInsertDSParameters == null)
                                                {
                                                    logRecode.Info("7");
                                                    ret.Map_Args[argmap["waybill_num"]] = "e";  //该运单参数错误
                                                    continue;
                                                }
                                                 exret = MySqlHelper.ExecuteNonQuery(con, commandInsertDSText, commandInsertDSParameters);
                                                if (exret != 1)
                                                {
                                                    logRecode.Info("8");
                                                    ret.Map_Args[argmap["waybill_num"]] = "f";  //该运单插入数据库错误
                                                    continue;
                                                }

                                            }
                                            //计算成功和失败统计
                                            int cnt = Convert.ToInt32(ret.Map_Args["SCount"]);
                                            cnt++;
                                            ret.Map_Args["SCount"] = cnt.ToString();

                                            cnt = Convert.ToInt32(ret.Map_Args["DFCount"]);
                                            cnt--;
                                            ret.Map_Args["DFCount"] = cnt.ToString();
                                            logRecode.Info("00:" + " SCount=" + ret.Map_Args["SCount"] + "; DFCount=" + ret.Map_Args["DFCount"]);
                                            #endregion
                                        }
                                        else
                                        {
                                            #region //删除状态运单

                                            try
                                            {
                                                //插入新单
                                                MySqlParameter[] commandInsertParameters = GetMySqlParameters(argmap, true);
                                                if (commandInsertParameters == null)
                                                {
                                                    logRecode.Info("11");
                                                    ret.Map_Args[argmap["waybill_num"]] = "e";  //该运单参数错误
                                                    continue;
                                                }
                                                int exret = MySqlHelper.ExecuteNonQuery(con, commandInsertDelText, commandInsertParameters);
                                                if (exret != 1)
                                                {
                                                    logRecode.Info("12");
                                                    ret.Map_Args[argmap["waybill_num"]] = "f";  //该运单插入数据库错误
                                                    continue;
                                                }

                                                //插入新操作记录
                                                MySqlParameter[] commandInsertRCParameters = GetMySqlParametersRC(argmap, false);
                                                if (commandInsertRCParameters == null)
                                                {
                                                    logRecode.Info("14");
                                                    ret.Map_Args[argmap["waybill_num"]] = "e";  //该运单参数错误
                                                    continue;
                                                }
                                                exret = MySqlHelper.ExecuteNonQuery(con, commandInsertRCText, commandInsertRCParameters);
                                                if (exret != 1)
                                                {
                                                    logRecode.Info("15");
                                                    ret.Map_Args[argmap["waybill_num"]] = "f";  //该运单插入数据库错误
                                                    continue;
                                                }
                                                //插入新删除操作记录
                                                commandInsertRCParameters = GetMySqlParametersRC(argmap, true);
                                                if (commandInsertRCParameters == null)
                                                {
                                                    logRecode.Info("16");
                                                    ret.Map_Args[argmap["waybill_num"]] = "e";  //该运单参数错误
                                                    continue;
                                                }
                                                exret = MySqlHelper.ExecuteNonQuery(con, commandInsertRCText, commandInsertRCParameters);
                                                if (exret != 1)
                                                {
                                                    logRecode.Info("17");
                                                    ret.Map_Args[argmap["waybill_num"]] = "f";  //该运单插入数据库错误
                                                    continue;
                                                }
                                            }
                                            catch (Exception e)
                                            {
                                                logRecode.Info("提交删除运单失败 : " + e.Message + ",运单:" + argmap["waybill_num"]);
                                            }
                                  

                                            #endregion
                                        }

                                        ret.Map_Args[argmap["waybill_num"]] = "s";  //插入运单成功
                                        logRecode.Info("000");
                                    }
                                }
                                #endregion

                                con.Close();
                            }

                            tsone.Complete();
                        }
                    }
                    catch (Exception e)
                    {
                        logRecode.Info("gogogo_3 e = " + e.Message);
                        foreach (Dictionary<string, string> argmap in temp_tslist)
                        {
                            ret.Map_Args[argmap["waybill_num"]] = "i";  //事务异常 置位为未执行
                        }
                    }

                    temp_tslist.Clear();
                }

            }
            catch (Exception e)
            {
                logRecode.Info("gogogo_4 e = " + e.Message);
                logRecode.Info("20");
            }

            ret.Map_Args["ErrorMsg"] = "";  //有效返回
            ret.Byte_Flag = (sbyte)0;
            return ret;
        }

        #endregion

        #endregion  //新手机接口==================================================




        #region //新PC接口==================================================

        //立即刷新短信开始发送
        private static void RefreshNow(string company, int smscount)
        {
            Refresher.Refresher.RefreshNow(company, smscount);
        }


        /* 网点软件短信自动发送接口
         * 
         * SmsType: 1运单建立短信（外部短信）
         *          2运单到港短信（外部短信）
         *          4车次装车短信（内部短信）
         *          5车次发车短信（内部短信）
         *          6车次到港短信（内部短信）
         *          7车次完结短信（内部短信）
         *          8代收回账短信（内部短信）
         * 
         * Phonecount:有效电话数
         * Account:网点账号
         * UserAccount:员工账号
         * Password:员工密码
         * 
         * ret: 2网点剩余短信条数不足
         *      1公司剩余短信条数不足
         *      0成功
         *      -1公司或网点账号不存在
         *      -2员工账号密码不匹配
         *      -3数据库错误
         *      -4参数错误
         *      
         *      
        /************************************************************************/
        public static ComThriftMsg Net_AutoSendSMSNew(string msg)
        {
            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            try
            {
                #region //反序列化

                byte[] bytrcv = Convert.FromBase64String(msg);
                ComThriftMsg comrcv = CommonTools.ByteTOComThriftAESD(bytrcv);

                if (!comrcv.__isset.struct_sqlinfo)
                {
                    ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                    return ret;
                }
                else
                {
                    if (!(comrcv.Struct_sqlinfo.__isset.string_sqlip && comrcv.Struct_sqlinfo.__isset.string_sqlname && comrcv.Struct_sqlinfo.__isset.string_sqlport
                        && comrcv.Struct_sqlinfo.__isset.string_sqlpwd && comrcv.Struct_sqlinfo.__isset.string_sqluser && comrcv.Struct_sqlinfo.__isset.string_useridkey))
                    {
                        ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                        return ret;
                    }
                }

                if (!comrcv.__isset.map_Args)
                {
                    ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                    return ret;
                }
                else
                {
                    if (!comrcv.Map_Args.Keys.Contains("Phonecount") || !comrcv.Map_Args.Keys.Contains("PhoneNumbers")
                        || !comrcv.Map_Args.Keys.Contains("SmsText") || !comrcv.Map_Args.Keys.Contains("SmsType"))
                    {
                        ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                        return ret;
                    }
                    else
                    {
                        if (!(comrcv.Map_Args["SmsType"] == "1" || comrcv.Map_Args["SmsType"] == "2" || comrcv.Map_Args["SmsType"] == "4"
                            || comrcv.Map_Args["SmsType"] == "5" || comrcv.Map_Args["SmsType"] == "6" || comrcv.Map_Args["SmsType"] == "7" || comrcv.Map_Args["SmsType"] == "8"))
                        {
                            ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                            return ret;
                        }
                    }
                }

                #endregion

                #region //效验IDkey

                DataRow dr_loginfo = CheckNetIdkey(comrcv.Struct_sqlinfo);
                if (dr_loginfo == null)
                {
                    ret.Map_Args["ErrorMsg"] = "IDKey无效";
                    return ret;
                }

                #endregion

                #region //生成数据量连接信息

                MySqlHelperEx mysqlhelperexImpl = new MySqlHelperEx();
                mysqlhelperexImpl.DB_CharacterSet = "utf8";

                mysqlhelperexImpl.DB_Server = comrcv.Struct_sqlinfo.String_sqlip;
                mysqlhelperexImpl.DB_Database = comrcv.Struct_sqlinfo.String_sqlname;
                mysqlhelperexImpl.DB_Port = comrcv.Struct_sqlinfo.String_sqlport;
                mysqlhelperexImpl.DB_UserID = comrcv.Struct_sqlinfo.String_sqluser;
                //mysqlhelperexImpl.DB_Password = comrcv.Struct_sqlinfo.String_sqlpwd;
                mysqlhelperexImpl.DB_Password = MySqlPwd;

                #endregion

                #region //从数据库获取信息

                bool needresetError = true;
                try
                {
                    //检查本次发送时短信总剩余条数是否足够
                    //检查公司账户短信剩余条数是否足够
                    string commandText = string.Format("SELECT Smscount FROM {0} WHERE Account = ?companyAcc;", "smsmanager");
                    MySqlParameter[] msqlp = new MySqlParameter[1];
                    msqlp[0] = new MySqlParameter("?companyAcc", dr_loginfo["Log_companyaccount"].ToString());

                    object obj_smscpy = mysqlhelperexImpl.ExecuteScalar(commandText, msqlp);
                    if (obj_smscpy == null)
                    {
                        ret.Map_Args["ErrorMsg"] = "公司账号不存在";
                        return ret;
                    }

                    //检查网点账户短信剩余条数是否足够
                    commandText = string.Format("SELECT Smscount FROM {0} WHERE Account = ?netAcc;", dr_loginfo["Log_companyaccount"].ToString() + DOWNUSERBIAONAME);
                    msqlp = new MySqlParameter[1];
                    msqlp[0] = new MySqlParameter("?netAcc", dr_loginfo["Log_netaccount"].ToString());

                    object obj_smsnet = mysqlhelperexImpl.ExecuteScalar(commandText, msqlp);
                    if (obj_smsnet == null)
                    {
                        ret.Map_Args["ErrorMsg"] = "网点账号不存在";
                        return ret;
                    }

                    //检查短信是否足够
                    if (Convert.ToInt32(obj_smscpy) < Convert.ToInt32(comrcv.Map_Args["Phonecount"]))
                    {
                        ret.Map_Args["ErrorMsg"] = "公司短信剩余不足";
                        needresetError = false;
                    }
                    if (Convert.ToInt32(obj_smsnet) < Convert.ToInt32(comrcv.Map_Args["Phonecount"]))
                    {
                        if (comrcv.Map_Args["SmsType"] == "1" || comrcv.Map_Args["SmsType"] == "2")   //外部短信
                        {
                            ret.Map_Args["ErrorMsg"] = "网点短信剩余不足";
                            needresetError = false;
                        }
                    }

                    //将待发短信存数据库
                    commandText = string.Format("INSERT INTO {0} VALUES (NULL, ?netAcc, ?netName, ?smsPhone, ?smsText, ?sendTime, ?smsStatus, ?smsType, ?worker, ?companyAcc);"
                        , dr_loginfo["Log_companyaccount"].ToString() + "biaosmsneedsend");
                    msqlp = new MySqlParameter[9];
                    msqlp[0] = new MySqlParameter("?netAcc", dr_loginfo["Log_netaccount"].ToString());
                    msqlp[1] = new MySqlParameter("?netName", dr_loginfo["Log_netname"].ToString());
                    msqlp[2] = new MySqlParameter("?smsPhone", comrcv.Map_Args["PhoneNumbers"]);
                    msqlp[3] = new MySqlParameter("?smsText", comrcv.Map_Args["SmsText"]);
                    msqlp[4] = new MySqlParameter("?sendTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                    msqlp[5] = new MySqlParameter("?smsStatus", "1");
                    msqlp[6] = new MySqlParameter("?smsType", comrcv.Map_Args["SmsType"]);
                    msqlp[7] = new MySqlParameter("?worker", dr_loginfo["Log_ygname"].ToString());
                    msqlp[8] = new MySqlParameter("?companyAcc", dr_loginfo["Log_companyaccount"].ToString());

                    int exeret = mysqlhelperexImpl.ExecuteNonQuery(commandText, msqlp);
                    if (exeret < 1)
                    {
                        //插入新待发短信
                        ret.Map_Args["ErrorMsg"] = "数据库错误";  //数据库错误
                        return ret;
                    }
                }
                catch (System.Exception e)
                {
                    ret.Map_Args["ErrorMsg"] = e.Message;
                    return ret;
                }

                #endregion

                #region //组装返回值

                if (needresetError)
                {
                    ret.Map_Args["ErrorMsg"] = "";
                    ret.Byte_Flag = (sbyte)0;  //正常有效返回
                }
                else
                {
                    ret.Byte_Flag = (sbyte)-2;
                }

                //立即发送短信
              //  RefreshSmsNow(dr_loginfo["Log_companyaccount"].ToString(), 1);
                RefreshSmsNew(mysqlhelperexImpl, dr_loginfo["Log_companyaccount"].ToString());
                #endregion

            }
            catch (System.Exception e)
            {
                ret.Map_Args["ErrorMsg"] = e.Message;
                return ret;
            }

            return ret;
        }

        /* 公司软件短信自动发送接口
         * 
         * SmsType: 3代收到账短信（外部短信）
         *          9代收到账短信（内部短信）
         * 
         * Phonecount:有效电话数
         * Account:网点账号
         * UserAccount:员工账号
         * Password:员工密码
         * 
         * ret: 2网点剩余短信条数不足
         *      1公司剩余短信条数不足
         *      0成功
         *      -1公司或网点账号不存在
         *      -2员工账号密码不匹配
         *      -3数据库错误
         *      -4参数错误
         *      
         *      
        /************************************************************************/
        public static ComThriftMsg Company_AutoSendSMSNew(string msg)
        {
            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            try
            {
                #region //反序列化

                byte[] bytrcv = Convert.FromBase64String(msg);
                ComThriftMsg comrcv = CommonTools.ByteTOComThriftAESD(bytrcv);

                if (!comrcv.__isset.struct_sqlinfo)
                {
                    ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                    return ret;
                }
                else
                {
                    if (!(comrcv.Struct_sqlinfo.__isset.string_sqlip && comrcv.Struct_sqlinfo.__isset.string_sqlname && comrcv.Struct_sqlinfo.__isset.string_sqlport
                        && comrcv.Struct_sqlinfo.__isset.string_sqlpwd && comrcv.Struct_sqlinfo.__isset.string_sqluser && comrcv.Struct_sqlinfo.__isset.string_useridkey))
                    {
                        ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                        return ret;
                    }
                }

                if (!comrcv.__isset.map_Args)
                {
                    ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                    return ret;
                }
                else
                {
                    if (!comrcv.Map_Args.Keys.Contains("Phonecount") || !comrcv.Map_Args.Keys.Contains("PhoneNumbers")
                        || !comrcv.Map_Args.Keys.Contains("SmsText") || !comrcv.Map_Args.Keys.Contains("SmsType"))
                    {
                        ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                        return ret;
                    }
                    else
                    {
                        if (!(comrcv.Map_Args["SmsType"] == "1" || comrcv.Map_Args["SmsType"] == "2" || comrcv.Map_Args["SmsType"] == "4"
                            || comrcv.Map_Args["SmsType"] == "5" || comrcv.Map_Args["SmsType"] == "6" || comrcv.Map_Args["SmsType"] == "7" || comrcv.Map_Args["SmsType"] == "8"))
                        {
                            ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                            return ret;
                        }
                    }
                }

                #endregion

                #region //效验IDkey

                DataRow dr_loginfo = CheckNetIdkey(comrcv.Struct_sqlinfo);
                if (dr_loginfo == null)
                {
                    ret.Map_Args["ErrorMsg"] = "IDKey无效";
                    return ret;
                }

                #endregion

                #region //生成数据量连接信息

                MySqlHelperEx mysqlhelperexImpl = new MySqlHelperEx();
                mysqlhelperexImpl.DB_CharacterSet = "utf8";

                mysqlhelperexImpl.DB_Server = comrcv.Struct_sqlinfo.String_sqlip;
                mysqlhelperexImpl.DB_Database = comrcv.Struct_sqlinfo.String_sqlname;
                mysqlhelperexImpl.DB_Port = comrcv.Struct_sqlinfo.String_sqlport;
                mysqlhelperexImpl.DB_UserID = comrcv.Struct_sqlinfo.String_sqluser;
                //mysqlhelperexImpl.DB_Password = comrcv.Struct_sqlinfo.String_sqlpwd;
                mysqlhelperexImpl.DB_Password = MySqlPwd;

                #endregion

                #region //从数据库获取信息

                bool needresetError = true;
                try
                {
                    //检查本次发送时短信总剩余条数是否足够
                    //检查公司账户短信剩余条数是否足够
                    string commandText = string.Format("SELECT Smscount FROM {0} WHERE Account = ?companyAcc;", "smsmanager");
                    MySqlParameter[] msqlp = new MySqlParameter[1];
                    msqlp[0] = new MySqlParameter("?companyAcc", dr_loginfo["Log_companyaccount"].ToString());

                    object obj_smscpy = mysqlhelperexImpl.ExecuteScalar(commandText, msqlp);
                    if (obj_smscpy == null)
                    {
                        ret.Map_Args["ErrorMsg"] = "公司账号不存在";
                        return ret;
                    }

                    //检查短信是否足够
                    if (Convert.ToInt32(obj_smscpy) < Convert.ToInt32(comrcv.Map_Args["Phonecount"]))
                    {
                        ret.Map_Args["ErrorMsg"] = "公司短信剩余不足";
                        needresetError = false;
                    }

                    //将待发短信存数据库
                    commandText = string.Format("INSERT INTO {0} VALUES (NULL, ?netAcc, ?netName, ?smsPhone, ?smsText, ?sendTime, ?smsStatus, ?smsType, ?worker, ?companyAcc);"
                        , dr_loginfo["Log_companyaccount"].ToString() + "biaosmsneedsend");
                    msqlp = new MySqlParameter[9];
                    msqlp[0] = new MySqlParameter("?netAcc", dr_loginfo["Log_netaccount"].ToString());
                    msqlp[1] = new MySqlParameter("?netName", dr_loginfo["Log_netname"].ToString());
                    msqlp[2] = new MySqlParameter("?smsPhone", comrcv.Map_Args["PhoneNumbers"]);
                    msqlp[3] = new MySqlParameter("?smsText", comrcv.Map_Args["SmsText"]);
                    msqlp[4] = new MySqlParameter("?sendTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                    msqlp[5] = new MySqlParameter("?smsStatus", "1");
                    msqlp[6] = new MySqlParameter("?smsType", comrcv.Map_Args["SmsType"]);
                    msqlp[7] = new MySqlParameter("?worker", dr_loginfo["Log_ygname"].ToString());
                    msqlp[8] = new MySqlParameter("?companyAcc", dr_loginfo["Log_companyaccount"].ToString());

                    int exeret = mysqlhelperexImpl.ExecuteNonQuery(commandText, msqlp);
                    if (exeret < 1)
                    {
                        //插入新待发短信
                        ret.Map_Args["ErrorMsg"] = "数据库错误";  //数据库错误
                        return ret;
                    }
                }
                catch (System.Exception e)
                {
                    ret.Map_Args["ErrorMsg"] = e.Message;
                    return ret;
                }

                #endregion

                #region //组装返回值

                if (needresetError)
                {
                    ret.Map_Args["ErrorMsg"] = "";
                    ret.Byte_Flag = (sbyte)0;  //正常有效返回
                }
                else
                {
                    ret.Byte_Flag = (sbyte)-2;
                }

                //立即发送短信
              //  RefreshNow(dr_loginfo["Log_companyaccount"].ToString(), 1);
                RefreshSmsNew(mysqlhelperexImpl, dr_loginfo["Log_companyaccount"].ToString());
                #endregion

            }
            catch (System.Exception e)
            {
                ret.Map_Args["ErrorMsg"] = e.Message;
                return ret;
            }

            return ret;
        }

        /* 网点软件短信手动发送接口（外部短信）
         * 
         * 
         * Phonecount:有效电话数
         * Account:网点账号
         * UserAccount:员工账号
         * Password:员工密码
         * 
         * ret: 2网点剩余短信条数不足
         *      1公司剩余短信条数不足
         *      0成功
         *      -1公司或网点账号不存在
         *      -2员工账号密码不匹配
         *      -3数据库错误
         *      
         *      
        /************************************************************************/
        public static ComThriftMsg Net_ManualSendSMSNew(string msg)
        {
            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            try
            {
                #region //反序列化

                byte[] bytrcv = Convert.FromBase64String(msg);
                ComThriftMsg comrcv = CommonTools.ByteTOComThriftAESD(bytrcv);

                if (!comrcv.__isset.struct_sqlinfo)
                {
                    ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                    return ret;
                }
                else
                {
                    if (!(comrcv.Struct_sqlinfo.__isset.string_sqlip && comrcv.Struct_sqlinfo.__isset.string_sqlname && comrcv.Struct_sqlinfo.__isset.string_sqlport
                        && comrcv.Struct_sqlinfo.__isset.string_sqlpwd && comrcv.Struct_sqlinfo.__isset.string_sqluser && comrcv.Struct_sqlinfo.__isset.string_useridkey))
                    {
                        ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                        return ret;
                    }
                }

                if (!comrcv.__isset.map_Args)
                {
                    ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                    return ret;
                }
                else
                {
                    if (!comrcv.Map_Args.Keys.Contains("Phonecount") || !comrcv.Map_Args.Keys.Contains("PhoneNumbers")
                        || !comrcv.Map_Args.Keys.Contains("SmsText"))
                    {
                        ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                        return ret;
                    }
                }

                #endregion

                #region //效验IDkey

                DataRow dr_loginfo = CheckNetIdkey(comrcv.Struct_sqlinfo);
                if (dr_loginfo == null)
                {
                    ret.Map_Args["ErrorMsg"] = "IDKey无效";
                    return ret;
                }

                #endregion

                #region //生成数据量连接信息

                MySqlHelperEx mysqlhelperexImpl = new MySqlHelperEx();
                mysqlhelperexImpl.DB_CharacterSet = "utf8";

                mysqlhelperexImpl.DB_Server = comrcv.Struct_sqlinfo.String_sqlip;
                mysqlhelperexImpl.DB_Database = comrcv.Struct_sqlinfo.String_sqlname;
                mysqlhelperexImpl.DB_Port = comrcv.Struct_sqlinfo.String_sqlport;
                mysqlhelperexImpl.DB_UserID = comrcv.Struct_sqlinfo.String_sqluser;
                //mysqlhelperexImpl.DB_Password = comrcv.Struct_sqlinfo.String_sqlpwd;
                mysqlhelperexImpl.DB_Password = MySqlPwd;

                #endregion

                #region //从数据库获取信息

                bool needresetError = true;
                string SmsType = "11";  //网点手动发送短信类型

                try
                {
                    //检查本次发送时短信总剩余条数是否足够
                    //检查公司账户短信剩余条数是否足够
                    string commandText = string.Format("SELECT Smscount FROM {0} WHERE Account = ?companyAcc;", "smsmanager");
                    MySqlParameter[] msqlp = new MySqlParameter[1];
                    msqlp[0] = new MySqlParameter("?companyAcc", dr_loginfo["Log_companyaccount"].ToString());

                    object obj_smscpy = mysqlhelperexImpl.ExecuteScalar(commandText, msqlp);
                    if (obj_smscpy == null)
                    {
                        ret.Map_Args["ErrorMsg"] = "公司账号不存在";
                        return ret;
                    }

                    //检查网点账户短信剩余条数是否足够
                    commandText = string.Format("SELECT Smscount FROM {0} WHERE Account = ?netAcc;", dr_loginfo["Log_companyaccount"].ToString() + DOWNUSERBIAONAME);
                    msqlp = new MySqlParameter[1];
                    msqlp[0] = new MySqlParameter("?netAcc", dr_loginfo["Log_netaccount"].ToString());
                    object obj_smsnet = mysqlhelperexImpl.ExecuteScalar(commandText, msqlp);
                    if (obj_smsnet == null)
                    {
                        ret.Map_Args["ErrorMsg"] = "网点账号不存在";
                        return ret;
                    }

                    //检查短信是否足够
                    if (Convert.ToInt32(obj_smscpy) < Convert.ToInt32(comrcv.Map_Args["Phonecount"]))
                    {
                        ret.Map_Args["ErrorMsg"] = "公司短信剩余不足";
                        needresetError = false;
                    }
                    if (Convert.ToInt32(obj_smsnet) < Convert.ToInt32(comrcv.Map_Args["Phonecount"]))
                    {
                        ret.Map_Args["ErrorMsg"] = "网点短信剩余不足";
                        needresetError = false;
                    }

                    //将待发短信存数据库
                    commandText = string.Format("INSERT INTO {0} VALUES (NULL, ?netAcc, ?netName, ?smsPhone, ?smsText, ?sendTime, ?smsStatus, ?smsType, ?worker, ?companyAcc);"
                        , dr_loginfo["Log_companyaccount"].ToString() + "biaosmsneedsend");
                    msqlp = new MySqlParameter[9];
                    msqlp[0] = new MySqlParameter("?netAcc", dr_loginfo["Log_netaccount"].ToString());
                    msqlp[1] = new MySqlParameter("?netName", dr_loginfo["Log_netname"].ToString());
                    msqlp[2] = new MySqlParameter("?smsPhone", comrcv.Map_Args["PhoneNumbers"]);
                    msqlp[3] = new MySqlParameter("?smsText", comrcv.Map_Args["SmsText"]);
                    msqlp[4] = new MySqlParameter("?sendTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                    msqlp[5] = new MySqlParameter("?smsStatus", "1");
                    msqlp[6] = new MySqlParameter("?smsType", SmsType);
                    msqlp[7] = new MySqlParameter("?worker", dr_loginfo["Log_ygname"].ToString());
                    msqlp[8] = new MySqlParameter("?companyAcc", dr_loginfo["Log_companyaccount"].ToString());

                    int exeret = mysqlhelperexImpl.ExecuteNonQuery(commandText, msqlp);
                    if (exeret < 1)
                    {
                        //插入新待发短信
                        ret.Map_Args["ErrorMsg"] = "数据库错误";  //数据库错误
                        return ret;
                    }
                }
                catch (System.Exception e)
                {
                    ret.Map_Args["ErrorMsg"] = e.Message;
                    return ret;
                }

                #endregion

                #region //组装返回值

                if (needresetError)
                {
                    ret.Map_Args["ErrorMsg"] = "";
                    ret.Byte_Flag = (sbyte)0;  //正常有效返回
                }
                else
                {
                    ret.Byte_Flag = (sbyte)-2;
                }

                //立即发送短信
              //  RefreshNow(dr_loginfo["Log_companyaccount"].ToString(), 1);
                RefreshSmsNew(mysqlhelperexImpl, dr_loginfo["Log_companyaccount"].ToString());
                #endregion

            }
            catch (System.Exception e)
            {
                ret.Map_Args["ErrorMsg"] = e.Message;
                return ret;
            }

            return ret;
        }

        /* 公司软件短信手动发送接口（内部短信）
         * 
         * Phonecount:有效电话数
         * Account:公司账号
         * UserAccount:员工账号
         * Password:员工密码
         * 
         * ret: 1公司剩余短信条数不足
         *      0成功
         *      -1公司账号不存在
         *      -2员工账号密码不匹配
         *      -3数据库错误
         *      -4获取数量出错
         *      
        /************************************************************************/
        public static ComThriftMsg Company_ManualSendSMSNew(string msg)
        {
            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            try
            {
                #region //反序列化

                byte[] bytrcv = Convert.FromBase64String(msg);
                ComThriftMsg comrcv = CommonTools.ByteTOComThriftAESD(bytrcv);

                if (!comrcv.__isset.struct_sqlinfo)
                {
                    ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                    return ret;
                }
                else
                {
                    if (!(comrcv.Struct_sqlinfo.__isset.string_sqlip && comrcv.Struct_sqlinfo.__isset.string_sqlname && comrcv.Struct_sqlinfo.__isset.string_sqlport
                        && comrcv.Struct_sqlinfo.__isset.string_sqlpwd && comrcv.Struct_sqlinfo.__isset.string_sqluser && comrcv.Struct_sqlinfo.__isset.string_useridkey))
                    {
                        ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                        return ret;
                    }
                }

                if (!comrcv.__isset.map_Args)
                {
                    ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                    return ret;
                }
                else
                {
                    if (!comrcv.Map_Args.Keys.Contains("Phonecount") || !comrcv.Map_Args.Keys.Contains("PhoneNumbers")
                        || !comrcv.Map_Args.Keys.Contains("SmsText"))
                    {
                        ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                        return ret;
                    }
                }

                #endregion

                #region //效验IDkey

                DataRow dr_loginfo = CheckNetIdkey(comrcv.Struct_sqlinfo);
                if (dr_loginfo == null)
                {
                    ret.Map_Args["ErrorMsg"] = "IDKey无效";
                    return ret;
                }

                #endregion

                #region //生成数据量连接信息

                MySqlHelperEx mysqlhelperexImpl = new MySqlHelperEx();
                mysqlhelperexImpl.DB_CharacterSet = "utf8";

                mysqlhelperexImpl.DB_Server = comrcv.Struct_sqlinfo.String_sqlip;
                mysqlhelperexImpl.DB_Database = comrcv.Struct_sqlinfo.String_sqlname;
                mysqlhelperexImpl.DB_Port = comrcv.Struct_sqlinfo.String_sqlport;
                mysqlhelperexImpl.DB_UserID = comrcv.Struct_sqlinfo.String_sqluser;
                //mysqlhelperexImpl.DB_Password = comrcv.Struct_sqlinfo.String_sqlpwd;
                mysqlhelperexImpl.DB_Password = MySqlPwd;

                #endregion

                #region //从数据库获取信息

                bool needresetError = true;
                string SmsType = "10";  //公司手动发送短信类型

                try
                {
                    //检查本次发送时短信总剩余条数是否足够
                    //检查公司账户短信剩余条数是否足够
                    string commandText = string.Format("SELECT Smscount FROM {0} WHERE Account = ?companyAcc;", "smsmanager");
                    MySqlParameter[] msqlp = new MySqlParameter[1];
                    msqlp[0] = new MySqlParameter("?companyAcc", dr_loginfo["Log_companyaccount"].ToString());

                    object obj_smscpy = mysqlhelperexImpl.ExecuteScalar(commandText, msqlp);
                    if (obj_smscpy == null)
                    {
                        ret.Map_Args["ErrorMsg"] = "公司账号不存在";
                        return ret;
                    }

                    //检查短信是否足够
                    if (Convert.ToInt32(obj_smscpy) < Convert.ToInt32(comrcv.Map_Args["Phonecount"]))
                    {
                        ret.Map_Args["ErrorMsg"] = "公司短信剩余不足";
                        needresetError = false;
                    }

                    //将待发短信存数据库
                    commandText = string.Format("INSERT INTO {0} VALUES (NULL, ?netAcc, ?netName, ?smsPhone, ?smsText, ?sendTime, ?smsStatus, ?smsType, ?worker, ?companyAcc);"
                        , dr_loginfo["Log_companyaccount"].ToString() + "biaosmsneedsend");
                    msqlp = new MySqlParameter[9];
                    msqlp[0] = new MySqlParameter("?netAcc", dr_loginfo["Log_netaccount"].ToString());
                    msqlp[1] = new MySqlParameter("?netName", dr_loginfo["Log_netname"].ToString());
                    msqlp[2] = new MySqlParameter("?smsPhone", comrcv.Map_Args["PhoneNumbers"]);
                    msqlp[3] = new MySqlParameter("?smsText", comrcv.Map_Args["SmsText"]);
                    msqlp[4] = new MySqlParameter("?sendTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                    msqlp[5] = new MySqlParameter("?smsStatus", "1");
                    msqlp[6] = new MySqlParameter("?smsType", SmsType);
                    msqlp[7] = new MySqlParameter("?worker", dr_loginfo["Log_ygname"].ToString());
                    msqlp[8] = new MySqlParameter("?companyAcc", dr_loginfo["Log_companyaccount"].ToString());

                    int exeret = mysqlhelperexImpl.ExecuteNonQuery(commandText, msqlp);
                    if (exeret < 1)
                    {
                        //插入新待发短信
                        ret.Map_Args["ErrorMsg"] = "数据库错误";  //数据库错误
                        return ret;
                    }
                }
                catch (System.Exception e)
                {
                    ret.Map_Args["ErrorMsg"] = e.Message;
                    return ret;
                }

                #endregion

                #region //组装返回值

                if (needresetError)
                {
                    ret.Map_Args["ErrorMsg"] = "";
                    ret.Byte_Flag = (sbyte)0;  //正常有效返回
                }
                else
                {
                    ret.Byte_Flag = (sbyte)-2;
                }

                //立即发送短信
                RefreshSmsNew(mysqlhelperexImpl,dr_loginfo["Log_companyaccount"].ToString());

                #endregion

            }
            catch (System.Exception e)
            {
                ret.Map_Args["ErrorMsg"] = e.Message;
                return ret;
            }

            return ret;
        }


        public static void RefreshSmsNew(MySqlHelperEx mysqlhelperexImpl, string account)
        {
            string commandText = string.Format("update smsmanager set Nullflag='1' where  Account=?Acc;");
            MySqlParameter[]  msqlp = new MySqlParameter[1];
            msqlp[0] = new MySqlParameter("?Acc", account);
            mysqlhelperexImpl.ExecuteNonQuery(commandText, msqlp);
        }
  
        #endregion

        //从路由服务器获取信息
        public static ComThriftMsg getAppServerNodeSdp(string userid)
        {
            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            try
            {
                #region //获取节点服务器信息
                MySqlHelperEx mysqlhelperexImpl = new MySqlHelperEx();
                string commandText = string.Format("SELECT * FROM routingservice WHERE UserId = ?userid;");
                MySqlParameter[] msqlp = new MySqlParameter[1];
                msqlp[0] = new MySqlParameter("?userid", userid);

                DataSet ds_service = mysqlhelperexImpl.ExecuteDataset(connectionRoutingString, commandText, msqlp);

                if (ds_service == null)
                {
                    //公司账号不存在
                    ret.Map_Args["ErrorMsg"] = "公司账号不存在";
                    return ret;
                }
                if (ds_service.Tables.Count == 0)
                {
                    //公司账号不存在
                    ret.Map_Args["ErrorMsg"] = "公司账号不存在";
                    return ret;
                }
                bool ishaverows = false;
                foreach (DataTable dt in ds_service.Tables)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        if (dt.Columns.Contains("UserId"))
                        {
                            ishaverows = true;
                            break;
                        }
                    }
                }
                if (!ishaverows)
                {
                    //公司账号不存在
                    ret.Map_Args["ErrorMsg"] = "公司账号不存在";
                    return ret;
                }

                ret.List_MapArgs = new List<Dictionary<string, string>>();

                bool setfirstone = false;
                foreach (DataTable dt in ds_service.Tables)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        Dictionary<string, string> mapimpl = new Dictionary<string, string>();
                        foreach (DataColumn dc in dt.Columns)
                        {
                            mapimpl.Add(dc.ColumnName, dr[dc.ColumnName].ToString());
                        }
                        ret.List_MapArgs.Add(mapimpl);

                        if (!setfirstone)
                        {
                            ret.Struct_sqlinfo = new SqlInfo();
                            ret.Struct_sqlinfo.String_sqlip = dr["DbAddr"].ToString();
                            ret.Struct_sqlinfo.String_sqlname = dr["DbName"].ToString();
                            ret.Struct_sqlinfo.String_sqlport = dr["DbPort"].ToString();
                            ret.Struct_sqlinfo.String_sqluser = dr["DbUser"].ToString();
                            ret.Struct_sqlinfo.String_sqlpwd = dr["DbPwd"].ToString();

                            ret.Map_Args.Add("ReadonlyFlag", "true");
                            ret.Map_Args.Add("ReadDbAddr", dr["ReadDbAddr"].ToString());
                            ret.Map_Args.Add("ReadDbPort", dr["ReadDbPort"].ToString());
                            ret.Map_Args.Add("ReadDbName", dr["ReadDbName"].ToString());
                            ret.Map_Args.Add("ReadDbUser", dr["ReadDbUser"].ToString());
                            ret.Map_Args.Add("ReadDbPwd", dr["ReadDbPwd"].ToString());

                            ret.Map_Args.Add("DbAddr", dr["DbAddr"].ToString());
                            ret.Map_Args.Add("DbPort", dr["DbPort"].ToString());
                            ret.Map_Args.Add("DbName", dr["DbName"].ToString());
                            ret.Map_Args.Add("DbUser", dr["DbUser"].ToString());
                            ret.Map_Args.Add("DbPwd", dr["DbPwd"].ToString());


                            ret.Struct_sqlinfo.String_useridkey = "";

                            setfirstone = true;
                        }
                    }
                }

                if (setfirstone)
                {
                    ret.Byte_Flag = (sbyte)0;
                    ret.Map_Args["ErrorMsg"] = "";
                }

                #endregion
            }
            catch (System.Exception e)
            {
                ret.Map_Args["ErrorMsg"] = e.Message;
                return ret;
            }
            return ret;
        }

    }
}
